i dont do it, it just happens
Obviously you are writing the replies though... Think maybe you need to get into the habit of proof reading your messages before you send them. If you're compulsively insulting people- you can modify your language before you hit 'send'.
Also- I think it's worth you trying to analyse why you're doing this. Presumably it's because you're feeling annoyed? What at?
Me for example- one particular friend will text me- 'How are you? How's it going?' (They already know it's likely going badly.) Normal really but I dread such a text because- I don't want to lie- but- if I tell the truth and say I'm struggling- they'll (maybe naturally) try and come up with things to try to 'help'... Except they don't help- they just annoy me further because they don't take their own advice and they don't like platitudes themselves. So- I'm getting to the point where I'm just going to ask them to stop asking me. Thing is- I know it's my own problem but- for the friendship to continue and be pleasant for both of us, we probably need to avoid that whole cycle.
Maybe you need to look at what it is they're saying that's annoying you. Why do you want them to stop saying certain things? If the friendships are important to you- maybe you can try and prevent those things being said to begin with- so you don't get triggered. If it's just compulsive though- I don't know... Maybe other things in life are making you frustrated and you're lashing out at those closest to you?