We've all seen it at one time or another. A big, nasty, hairy, cranky looking THING in our nice, clean, precious text file. How the hell did that get there?! More importantly... How do I get rid of it?
This condition can present itself in several ways, like the unprintable character code in angle brackets:
...an intimidatingly visible character from another land:
...or just fancy versions of good old regular ASCII characters:
I’m sick of ‘smart’ quotes
Navigating through your whole file looking for and exterminating these little warts by hand would be tedious and we're Vimmers after all, so we should be thinking in sharper tools, like... a whole buffer substitution. Great. Now we have a new problem... How do I type one of those eyesores into the substitute command...? We'll use a little dash of Register Pasting magic.
This could be an encoding problem, so make sure :set enc? fenc? return sane values before you go stripping out or replacing these crusty critters.
Let's take the smart quotes example and clean them up to be ordinary, normal, sane, plain quotes. We'll tackle that smart single quote case from above.
- Navigate on over to one of the offending ’ characters.
- Press xu
- Type :%s/<c-r>"/'/g
- Repeat for all of the other smarts in the file.