Skip to content

Instantly share code, notes, and snippets.

@Chunlin-Li
Last active February 2, 2016 06:44
Show Gist options
  • Save Chunlin-Li/94c7b0209cbfe9181273 to your computer and use it in GitHub Desktop.
Save Chunlin-Li/94c7b0209cbfe9181273 to your computer and use it in GitHub Desktop.
vim

编辑相关

自动缩进 set autoindent
缩进宽度 set tabstop=2

编码问题 encode

vim 中通常不修改 encoding 参数, 即使出现乱码, 通常也保持该值为 utf-8

文件被打开后, 就已经被 vim 从文件自身的编码转为 utf-8 编码了, 并且将 fileencoding 设置为文件自身编码, 当保存修改时, vim 会将文件编码为 fileencoding 表示的编码方式并保存, 因此如果修改了该参数并保存文件, 相当于对文件进行了转码. vim 命令例如: set fileencoding=gbk

vim 打开文件时会对文件编码方式进行探测, fileencodings 参数记录所有可能被探测的编码方式. 修改 .vimrc 文件, 并设置 :

set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

会按照顺序依次探测. 严格编码在前, 宽松编码在后. 这样在打开文件时, vim 就可以正确探测到对应的文件编码类型了.

参考:

http://edyfox.codecarver.org/html/vim_fileencodings_detection.html
vim encoding list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment