I’m torn. I’ve had to deal with people like Tim before, and a couple of times, I’ve lucked into the perfect response to shut them up, but it was never anything I planned.
Ignoring him when he’s being a dick would probably be easiest, since you can’t apply the really appropriate negative feedback (punch him in the balls) in the moment.
The direct confrontation takes skill and strength to pull off. Done right, you show him a mirror image of what he is and shame him into behaving. That’s rare. Done wrong, it just gives him more ammunition to use on you.
So, I think I’d go with middle of the road. Kill him with kindness.
It starts when you enter a room or say something or do something that gives him an opening. He makes a jerky comment. Don’t blow him off. Don’t look elsewhere. Don’t let it slide.
Put all your attention on him.
“Tim, are you okay? Do you need my attention? 'Cause that was such a [stupid/asshole/sarcastic/bullshit] thing to say, it sounds to me like you really need some attention.”
Next, if there are bystanders, bring them in on your side. Don’t let Tim get a word in edgewise. Talk over him if you must. Because you must. Tim is a man who needs your help and the help of all your friends.
“Hey, guys, I think Tim’s having a bad day. I mean, he just sounds so needy right now. I tell you what, why don’t we all [tell Tim what a great guy he is/give Tim a bunch of hugs/give Tim our undivided attention so he can tell us what’s wrong]?”
Then, impose on him. If he joked about how you could sit on the couch, sit right next to him. Put an arm around him. If he cracked a line about you eating dessert, bring him the entire dessert and a fork. If his girlfriend just made a remark about how he always picks on you, say it’s probably because he’s frustrated (winkwink), and maybe you could shoo everyone out of the room so they can have some “alone” time. Whatever it was he said, turn it around and make it about him.
At some point, Tim is going to scream that he’s fine. Take him at his word and back off.
The next time he says something rotten - anything to anyone - start it all over again.
And again.
And again.
Remain totally and completely sincere, because clearly he is a troubled soul in need of emotional support. Ask the others, ahead of time if you can, to support you, follow your lead, and continue with the strategy when you’re not there.
He needs to know that every time he opens his mouth and squeezes out a verbal turd, there are consequences for him. Unpleasant, aggravating, embarrassing, meaningful, and utterly polite consequences.