是否可以在文件中输入命令_gvimrc
来设置默认编码和行尾?
我正在使用 Windows 机器,但我想使用 UTF-8 编码(无 BOM)和标准 Unix 行尾(\n)创建和编辑文件。
我可以设置 Vim 来创建具有这些规范的文件吗?
是否可以在文件中输入命令_gvimrc
来设置默认编码和行尾?
我正在使用 Windows 机器,但我想使用 UTF-8 编码(无 BOM)和标准 Unix 行尾(\n)创建和编辑文件。
我可以设置 Vim 来创建具有这些规范的文件吗?
经过一段时间的阅读和实验:
将这些设置在_gvimrc
set encoding=utf-8 "Set default buffer encoding to UTF-8.
set fileencodings=utf-8,latin1 "Set the order of file encodings when reading and creating files.
set fileformats=unix,dos,mac "Set the order of line endings when reading and creating files.
这些应该在命令行中使用。
set fileencoding=utf-8 "Change an opened file's encoding.
set fileformat=unix "Change an opened file's line endings.
当然,把它放到你的 gvimrc 中:
set encoding=utf-8
set fileformat=unix
您可以使用该:h[elp]
命令获取其他信息,例如:h encoding
NOTE:
I realize that you specifically asked for a setting for your vimrc
file but I thought I would offer this bit of advice anyway because I suspect that you may benefit from it (you may be using both *nix and Windows like me).
I do work on both *nix and Windows and I have found it a lot easier to use the modeline
feature (see: :help modeline
) in lieu of setting the file format in my RC file. This allows me to have something like: vim:ff=unix
at the bottom of each file (This way, I do not have to worry about changing the line endings for a *nix makefile I happen to edit in/on Windows.
HTH
看看这个问题,它应该涵盖你所有的 vim 编码基础。
从链接的答案中引用,并添加您的行尾首选项:
set fileformats=unix,dos,mac
if has("multi_byte")
if &termencoding == ""
let &termencoding = &encoding
endif
set encoding=utf-8 " better default than latin1
setglobal fileencoding=utf-8 " change default file encoding when writing new files
endif