This is one of these things that I always need to look up. I know this tip will probably have no relevance for 98.5% of my regular readers, but I wanted to put it here for future reference. Also, since I just spent like 20 minutes googling the solution perhaps this can be of service for people who run into the same issue.
Today was the first time since I last reinstalled Windows when I needed to type something in Polish inside Vim and I realized that my Alt-gr combinations are not working. In other words I could not type letters such as ł, ą, ę, ż, ź, ś, ć, ó and etc.. You’d be surprised how often these come up in an average sentence. Surprisingly enough, I had no such problem on Ubuntu where they worked just fine. Windows version however refused to cooperate.
I did a quick google search for “vim polish characters” and got basically nothing. Then I tried few search queries in Polish and still got little info. Then I realized I was approaching this wrong, and my issue was caused by two factors:
- Vim was not in a Unicode compliant mode
- The font I was using (Bitstream Vera Sans Mono) was not Unicode friendly
So I set out to fix this. How do we get Unicode characters to work properly in Vim on Windows? Easy, just paste the following snipped into your _vimrc:
if has("multi_byte") if &termencoding == "" let &termencoding = &encoding endif set encoding=utf-8 setglobal fileencoding=utf-8 bomb set fileencodings=ucs-bom,utf-8,latin1 endif
Explanation can be found in Vim Tip #246. The if statement is a safety precaution since your version of the editor may not be compiled with the multi_byte feature which is required for Unicode to work properly.
Next you need a unicode friendly font. Bitstream Vera Sans Mono did not have the right Glyphs. Neither did Lucida Sans Typwriter. However Lucida Console, Curier New and the Consolas font all worked just fine. I really can’t tell you which fonts will work and which wont. You should probably just type some interesting word like “Gżegżółka” into the editor and just try different fonts until you find the one you like. For example Bitstream Vera Sans looks like this:
On the other hand Consolas font looks like this:
In my case I simply added the following line to _vimrc to change the font to Consolas:
I hope that someone will find this helpful. I’m posting it under a Google friendly title in case someone else needs to figure this out they can easily find it here. For those of you who could care less about Polish characters, vim or unicode I apologize. It had to be done. Now we can return to our usual brand of craziness that you came here to read. :P
[tags]vim, vi, unicode, polish letters, polish characters, ogonki[/tags]