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.
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: https://stackoverflow.com/questions/8121609/vims-encoding-options
And a handy link for vim's character encoding options is here: http://mindspill.net/computing/linux-notes/determine-and-change-file-character-encoding/
file your-file.txt
return?:set fileencoding?
. The file is probably encoded in UTF-8, Big5, or GB18030; you can probably get this information fromgedit
if that works correctly and then use:set fileencoding=...
in Vim to set it. If you're using Vim from a terminal, you may also need to correctly set that up for it to work correctly.