Fixing encoding in Vim

There were mysterious <92>, <93>, <94> and <96> tags in a text file. I found one solution to changing them from stackoverflow. However I found it after landing on atomic object’s blog post about character encoding tricks for vim that explains how to change encodings and check for character codes. It is as if I had learned this before, but something that I learned later pushed it away.

Finding <92> characters:

/\%x92

Replacing those characters with ‘:

:%s/\%x92/'/g

Changing the encoding of the file after the changes to utf-8 (when in doubt, use utf-8):

:set ++enc=UTF-8

On a related note, you can paste registers in command mode using ctrl+r. For example, copying a character <92> into register a ("ay), then pressing : for command mode and ctrl-r,a will paste <92> on to the (vim) command line.