全局配置 /usr/share/vim/vimrc,不建议修改。建议修改当前用户配置 ~/.vimrc,加载配置时会覆盖全局配置。
- 我的Vim配置,我只是轻量级用户,不像某些大佬(变态)
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 
 | syntax onset smartindent
 set autoindent
 set tabstop=4
 set shiftwidth=4
 set expandtab
 set softtabstop=4
 set ic "搜索忽略大小写
 set hlsearch
 set incsearch
 set number
 set ruler
 set cursorline
 set nocompatible "关闭vi兼容
 set nowrap "关闭超屏自动换行
 set encoding=utf-8
 set fileencodings=utf-8,ucs-bom,GB2312,big5
 filetype plugin indent on
 
 nnoremap . $
 nnoremap , ^
 nnoremap <F2> :set number!<CR>
 nnoremap <F3> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>
 nnoremap <F4> :set wrap!<CR>
 nnoremap <F5> :set hlsearch!<CR>
 
 "自动补全
 :inoremap ( ()<ESC>i
 :inoremap ) <c-r>=ClosePair(')')<CR>
 :inoremap { {<CR>}<ESC>O
 :inoremap } <c-r>=ClosePair('}')<CR>
 :inoremap [ []<ESC>i
 :inoremap ] <c-r>=ClosePair(']')<CR>
 :inoremap " ""<ESC>i
 :inoremap ' ''<ESC>i
 function! ClosePair(char)
 if getline('.')[col('.') - 1] == a:char
 return "\<Right>"
 else
 return a:char
 endif
 endfunction
 
 | 
Tips
- 主要设置语法高亮、智能缩进、高亮搜索、显示行号、编码格式
- 配置快捷键映射,,跳转到行首.跳转到行尾,F2开关显示行号,F3开关语法高亮,F4开关超屏换行,F5开关高亮搜索
- nnoremap中n表示normal模式,i表示insert模式,nore表示no recursion非递归映射,- <CR>表示回车
- 最后是设置智能补全
- .rc(run commands) 文件,通常在程序的启动阶段被调用
References