如何在vim中读取sjis编码的文件?

发布于 2024-09-30 22:20:13 字数 158 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北座城市 2024-10-07 22:20:13

您不应该想要更改 encoding 选项:它用于字符串的内部表示,仅当当前编码不包含所需编码中存在的字符时才应更改。如果您有时使用 sjis 编码编辑文件,那么

  1. 请确保 fileencodings 选项包含 sjis:将类似的内容放入 vimrc

    set fileencodings=ucs-bom,utf-8,sjis,默认
    
  2. 如果使用此选项 vim仍然无法正确识别文件编码,请使用 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 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).
挽清梦 2024-10-07 22:20:13

来自 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

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
皇甫轩 2024-10-07 22:20:13

对我来说,更改文件编码 (++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)都工作正常。

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:

set guifont=MS_Gothic:h9:cSHIFTJIS

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:

guifont=Monospace 10

And both display and input (with IBus Anthy IME) work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文