【发布时间】:2010-11-05 06:33:39
【问题描述】:
我有一个 html 文件,它是 shift-JIS 编码的(日语),我无法在 vim 下阅读它。设置 enc=cp932 或 enc=sjis 会产生垃圾。该文件在 emacs 中看起来不错,所以我猜这是特定于 vim 的。我该怎么做才能按原样阅读它(除了将其转换为像 utf-8 这样的健全编码之外)。
【问题讨论】:
我有一个 html 文件,它是 shift-JIS 编码的(日语),我无法在 vim 下阅读它。设置 enc=cp932 或 enc=sjis 会产生垃圾。该文件在 emacs 中看起来不错,所以我猜这是特定于 vim 的。我该怎么做才能按原样阅读它(除了将其转换为像 utf-8 这样的健全编码之外)。
【问题讨论】:
您不应该更改encoding 选项:它用于字符串的内部表示,并且仅当当前编码不包含所需编码中存在的字符时才应更改。如果你有时编辑带有sjis编码的文件,那么
请确保fileencodings 选项包含sjis:将类似的内容放入vimrc:
set fileencodings=ucs-bom,utf-8,sjis,default
e ++enc=sjis /path/to/file 打开文件。或者,如果文件已经打开,请使用e! ++enc=sjis(不带文件名)。【讨论】:
来自 vim 帮助:
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
【讨论】:
对我来说,更改文件编码 (++enc=) 在 Ubuntu Linux 上的 gVim 中可以正常工作,但在 Windows 7 上却不行(全部变成 ? 字符)。但我发现,即使不改变文件编码(默认 ucs-bom),我也可以通过改变 guifont 来显示日文字符:
set guifont=MS_Gothic:h9:cSHIFTJIS
但是,输入日文字符仍然不起作用(使用 Microsoft IME 输入日文会得到 ? 字符)。
只是为了比较,在 Linux 上我的 guifont 只是:
guifont=Monospace 10
显示和输入(使用 IBus Anthy IME)都可以正常工作。
【讨论】: