Vim search and replace on funky characters
Occasionally I run across weird characters in Vim that show up as numbers in angle brackets — <95>
or <97>
, for example. They’re just curly quotes and em-dashes and such, but they’re encoded oddly, and there’s no way easy to do a search and replace on them.
Except that there is.
- Yank the character. (That’s Vim talk for copying to the clipboard.)
- Start typing your search-and-replace command —
:%s/
- Hit
Ctrl-R
followed by"
(double quotes) to paste the character. - Finish out the rest of the search-and-replace and hit Enter —
:%s/<97>/--/g
Voila. (There might be a way to fix these characters with iconv or some other encoding app, but I haven’t been able to get it to work other than this way.)