How to read sjis-encoded file in vim?

I have an html file that is encoded using JS encoding (Japanese) and I can not read it under vim. Setting enc = cp932 or enc = sjis creates garbage. The file looks great in emacs, so I assume this is a specific vim. What can I do to read it as is (besides converting it to a normal encoding like utf-8).

+4
source share
3 answers

You should not change the encoding parameter: it is intended for the internal representation of strings and should only be changed if the current encoding does not contain characters that are present in the desired encoding. If you sometimes edit sjis encoded files, then

  • Make sure the fileencodings parameter contains sjis : put something like this in vimrc :

     set fileencodings=ucs-bom,utf-8,sjis,default 
  • If using this option vim still cannot correctly determine the file encoding, open the e ++enc=sjis /path/to/file . Or, if the file is already open, use e! ++enc=sjis e! ++enc=sjis (without file name).
+11
source

From vim help:

 There are a few encodings which are similar, but not exactly the same. Vim treats them as if they were different encodings, so that conversion will be done when needed. You might want to use the similar name to avoid conversion or when conversion is not possible: cp932, shift-jis, sjis cp936, euc-cn 
0
source

For me, changing fileencoding (++ enc =) works fine in gVim on Ubuntu Linux, but on Windows 7 it doesn't (does everything turn into characters?). But I found that even without changing fileencoding (ucs-bom by default), I could display Japanese characters just by changing guifont:

 set guifont=MS_Gothic:h9:cSHIFTJIS 

However, entering Japanese characters still doesn't work (using Microsoft IME to enter Japanese characters?).

Just for comparison, on Linux my guifont is simple:

 guifont=Monospace 10 

Both the display and the input (with IBus Anthy IME) work fine.

0
source

All Articles