How can I view a text file with Chinese characters in Vim?

I have a text file with Chinese characters. I can view it in gedit and it works fine, but when I try to open it with Vim I see things like:

»¹Ã»ºÃºÃ¸ßËÑÑ©»¨ÕÀ·ÅµÄÆøºò£¬ÄôÀÚ¹âÈáÈõºì´øÉÏÀ­²»Éϵľ糡°æ,

I am using Vim 7.04.

8

1 Answer

Some smart text editors try to guess which character encoding is being used. In this case, gedit got it right while Vim has chosen another character set that make sense to it...but is not quite what you expected. (It may have chosen this because you could have set a default encoding also.)

You can get the file's character encoding with the command line file -bi [filename].

You can get the current character set from the vim command :set fileencoding?

You can set the encoding with :set encoding=<encoding>

You'll probably find that it returns something like iso-8859-1. Whereas your file may be encoded in UTF-8, UTF-16 or Big5.

You can also set the file's encoding with :set fileencoding=<encoding>.

If you open the file and change the fileencoding, it will treat the file as modified and save it back in the new encoding.

For more information, you may want to read this SO question:

And a handy link for vim's character encoding options is here:

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like