打开该类型的文件时是否可以自动设置 UTF16 文件编码? [英] Is it possible to automatically set UTF16 file encoding when opening a file of that type?
问题描述
我用 Vim 编辑各种文件(我相信大多数 Vim 用户都会这样做).我遇到的一个 bug 是 Vim 在遇到带有奇怪编码的文件时所做的事情.大多数编辑器(这些天)在检测文件编码方面做得很好.但是,Vim 通常不会.你必须输入,例如:
I edit all kinds of files with Vim (as I'm sure most Vim users do). One bug bear I have is what Vim does when I come across a file with an odd encoding. Most editors (these days) make a good stab at detecting file encodings. However, Vim generally doesn't. And you have to type, for example:
:e ++enc=utf-16le
以UTF-16重新读取文件(否则你会得到大量@符号)
To re-read the file in UTF-16 (Otherwise you get a mass of @ signs)
我一直在四处寻找,看到了像 set_utf8.vim
这样的脚本,它可以检测特定的文件编码.但是,是否有更通用的解决方案?每次打开一个不寻常的文件时,我都不得不手动计算出文件编码是什么并咨询帮助,这让我有点厌烦.
I've been searching around and have seen scripts like set_utf8.vim
which can detect a specific file encoding. However, is there are more general solution? I'm a bit bored of having to manually work out what the file encoding is and consulting the help every time I open an unusual file.
推荐答案
将编码名称添加到 'fileencodings'
应该可以解决问题:
Adding the encoding name to 'fileencodings'
should do the trick:
:set fencs=ucs-bom,utf-16le,utf-8,default,latin1
Alternatively, there are plugins like AutoFenc and fencview.
这篇关于打开该类型的文件时是否可以自动设置 UTF16 文件编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!