【问题标题】:How to read sjis-encoded file in vim?如何在 vim 中读取 sjis 编码的文件?
【发布时间】:2010-11-05 06:33:39
【问题描述】:

我有一个 html 文件,它是 shift-JIS 编码的(日语),我无法在 vim 下阅读它。设置 enc=cp932 或 enc=sjis 会产生垃圾。该文件在 emacs 中看起来不错,所以我猜这是特定于 vim 的。我该怎么做才能按原样阅读它(除了将其转换为像 utf-8 这样的健全编码之外)。

【问题讨论】:

    标签: vim encoding


    【解决方案1】:

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

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

      set fileencodings=ucs-bom,utf-8,sjis,default
      
    2. 如果使用此选项 vim 仍然无法正确识别文件编码,请使用 e ++enc=sjis /path/to/file 打开文件。或者,如果文件已经打开,请使用e! ++enc=sjis(不带文件名)。

    【讨论】:

    • 哇,我没有注意到他试图更改“编码”而不是“文件编码”!你比我对。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-05
        • 1970-01-01
        • 2015-02-17
        • 2022-03-06
        • 1970-01-01
        • 2012-06-12
        • 1970-01-01
        • 2019-01-03
        相关资源
        最近更新 更多