Saturday, March 03, 2012

Set Vim in Windows to work with Unicode

My Windows has been installed and set for traditional Chinese environment and occasionally it makes some trouble when I need text files encoded in Unicode instead of Big5.

I've started to write some personal working logs in Markdown syntax with Vim. It's simple and quick. But when I tried to compile the plain text into HTML file, the Chinese characters introduced trouble for the Python implementation of Markdown. The error message was something like:
UnicodeDecodeError: 'utf8' codec can't decode byte
To prevent this kind of error, I thought the best approach was to make Vim work with Unicode in my Windows. The settings were added in C:\Program Files\Vim\_vimrc and they are as follows:

set fileencoding=utf8
set fileencodings=ucs-bom,utf-8,default,latin1

The first line tells Vim to save the text in utf8 and the second line gives Vim to open and convert the files in the given order of encoding.

No comments:

Post a Comment