Ben Crowder

Vim search and replace on funky characters

Vim

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.

  1. Yank the character. (That’s Vim talk for copying to the clipboard.)
  2. Start typing your search-and-replace command — :%s/
  3. Hit Ctrl-R followed by " (double quotes) to paste the character.
  4. 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.)

Comments

Rana Dutt on Apr 16, 2012 at 12:18 pm

Thanks so much! This saved me from a lot of work!

Rana

Add your two cents

Your comment was submitted and will show up as soon as I approve it. Thanks.
Something went wrong with submitting your comment. Try again, and if it still doesn't work, email me (). Sorry!