Replacing funny characters in Vim

Posted on 01 Dec 2012.

I have been using F5 to transcribe a bunch of interviews. Upon exporting the transcript, from .rtf to .txt, Swedish characters (å, ä, and ö) get funny placeholders, like '<9a>' for ö and '<8c>' for å. Additionally, '...' shows up as 'É'. I am not sure if this could be fixed using some encoding magic, but it can certainly be searched and replaced using vim. But merely typing in '<9a>' will not work, because that would make vim look for those actual characters and not the character we want to replace. The chareacted could be yanked into a buffer, but how does one paste it in command mode? Well, the lads and lasses in #vim at Freenode pointed me to this blog post explaining how. Check it out!

TL;DR: Yank the funny character into your buffer (go to the character, hit yl.) Then paste it into your search/replace command by hitting <c-r> and ". Full command: ':%s,<c-r>",foo,g,' — 'foo' being whatever you want to replace the character with.

blog comments powered by Disqus