Windows 下 vim 的配置文件在安装目录下,名为 _vimrc,常见配置如下:
01. vim 配色
color evening
02. vim 字体
set guifont=Courier_New:h14:cANSI
03. 不要使用 vi 的键盘模式,而是 vim 自己的
set nocompatible
04. 语法高亮
set syntax=on
05. 去掉输入错误的提示声音
set noeb
06. 在处理未保存或只读文件的时候,弹出确认
set confirm
07. 自动缩进
set autoindent
set cindent
08. 设置 Tab 的宽度
set tabstop=4
09. 缩进设置
set softtabstop=4
set shiftwidth=4
10. 不要用空格代替制表符
set noexpandtab
11. 在行和段开始处使用制表符
set smarttab
12. 显示行号
set number
13. 历史记录数
set history=1000
14. 禁止生成临时文件
set nobackup
15. 禁止生成交换文件
set noswapfile
16. 搜索忽略大小写
set ignorecase
17. 高亮搜索内容
set hlsearch
set incsearch
18. 行内替换
set gdefault
19. 高亮显示匹配的括号
set showmatch
20. 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=5
21. 为 C 程序提供自动缩进
set smartindent
22. 设置打开文件的默认编码
set encoding=utf-8
set fileencodings=utf-8,chinese,utf-16le,latin-1
if has(‘win32′)
set fileencoding=chinese
else
set fileencoding=utf-8
endif
23. 设置系统菜单的显示语言
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
24. 设置终端输出语言
language messages zh_CN.utf-8
25. 设置屏幕显示的编码
set termencoding=字符编码
常见问题解决:
1. 解决 Windows 下 vim 的中文乱码,添加 22,23,24 配置
2. 禁止 vim 自动生成以 ~ 为后缀的文件备份,添加 14 配置