Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read sjis-encoded file in vim?

Tags:

vim

encoding

I have an html file which is shift-JIS encoded (Japanese), and I cannot read it under vim. Setting enc=cp932 or enc=sjis generates garbage. The file looks fine in emacs, so I guess this is vim specific. What can I do to read it as is (besides converting it to a sane encoding like utf-8).

like image 962
David Cournapeau Avatar asked Nov 05 '10 06:11

David Cournapeau


1 Answers

You should not ever want to change encoding option: it is for internal representation of strings and should be changed only if current encoding does not contain characters present in desired encoding. If you sometimes edit files with sjis encoding, then

  1. Be sure, that fileencodings option contains sjis: put something like that into vimrc:

    set fileencodings=ucs-bom,utf-8,sjis,default
    
  2. If with this option vim still fails to recognize file encoding correctly, open your file with e ++enc=sjis /path/to/file. Or, if file is already opened, use e! ++enc=sjis (without filename).
like image 167
ZyX Avatar answered Nov 09 '22 22:11

ZyX