-3

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
  • 4
    Can you be more specific, please? What do you mean by "unreadable"? Do you see anything at all? If so, what do you see? What did you do to open vim? What command did you call? Feb 22, 2016 at 7:09
  • can'i show Chinese text in vim.
    – Z.Toy
    Feb 22, 2016 at 7:17
  • 1
    What does file your-file.txt return?
    – Thomas
    Feb 22, 2016 at 7:17
  • @z-toy If you're looking for viewing UTF-8 characters in vim, this question may be useful: stackoverflow.com/questions/5166652/… Feb 22, 2016 at 7:21
  • 3
    "Windows textfile" doesn't mean anything. The file is written using one character encoding, while Vim is assuming a different one. Hence you get the wrong characters. You can see the file encoding that Vim uses with :set fileencoding?. The file is probably encoded in UTF-8, Big5, or GB18030; you can probably get this information from gedit 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. Feb 22, 2016 at 8:38

1 Answer 1

2

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/

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .