如何在vim中读取sjis编码的文件?
我有一个 html 文件,它是 shift-JIS 编码的(日语),我无法在 vim 下读取它。设置 enc=cp932 或 enc=sjis 会生成垃圾。该文件在 emacs 中看起来很好,所以我猜这是 vim 特定的。我该怎么做才能按原样读取它(除了将其转换为像 utf-8 这样的正常编码之外)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不应该想要更改
encoding
选项:它用于字符串的内部表示,仅当当前编码不包含所需编码中存在的字符时才应更改。如果您有时使用sjis
编码编辑文件,那么请确保
fileencodings
选项包含sjis
:将类似的内容放入vimrc
:e ++enc=sjis /path/to/file
打开文件。或者,如果文件已打开,请使用e! ++enc=sjis
(没有文件名)。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 withsjis
encoding, thenBe sure, that
fileencodings
option containssjis
: put something like that intovimrc
:e ++enc=sjis /path/to/file
. Or, if file is already opened, usee! ++enc=sjis
(without filename).来自 vim 帮助:
From vim help:
对我来说,更改文件编码 (++enc=) 在 Ubuntu Linux 上的 gVim 中工作得很好,但在 Windows 7 上则不然(全部变成 ? 字符)。但我发现,即使不更改文件编码(默认 ucs-bom),我也可以通过更改 guifont 来显示日语字符:
但是,输入日语字符仍然不起作用(使用 Microsoft IME 键入日语会给出 ? 字符)。
只是为了比较,在 Linux 上我的 guifont 只是:
显示和输入(使用 IBus Anthy IME)都工作正常。
For me, changing fileencoding (++enc=) works fine in gVim on Ubuntu Linux, but on Windows 7 it doesn't (all turns into ? characters). But I found that even without changing fileencoding (default ucs-bom), I could display Japanese characters by just changing the guifont:
However, inputting Japanese characters still doesn't work (using the Microsoft IME to type Japanese gives ? characters).
Just for comparison, on Linux my guifont is just:
And both display and input (with IBus Anthy IME) work fine.