1、我用的是windows的GVIM.首先找到vimrc文件。用记事本打开。
2、然后添加以下内容:
"括号自动补全inoremap ( ()<LEFT>inoremap [ []<LEFT>inoremap { {}<LEFT>inoremap ' ''<LEFT>inoremap " ""<LEFT>
"F4键跳出括号:imap <F4> <esc>f)a:imap <F4> <esc>f]a
:imap <F4> <esc>f}a
:imap <F4> <esc>f'a
:imap <F4> <esc>f"a
3、解释说明,
自动补全是将括号的左边,映射为完整的括号,然后再回到括号里面去的命令。
跳出括号是将 F4键,映射为 Esc,然后输入f,然后输入括号的右边部分,在输入a,则光标定位到括号的右边。
你也可以自定义键,有人就用 :imap <TAB> <esc>f)a。这是讲Tab键映射为跳出括号。只是这样一来,tab键的缩进功能就失去了。
4、最后附上我自己的vimrc,供大家参考。
set nocompatiblesource $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswin
set fileencodings=ucs-bom,utf-8,utf-16,gbk,big5,gb18030,latin1set termencoding=utf-8set fileformats=unix,dosset encoding=prc
set diffexpr=MyDiff()function MyDiff() let opt = '-a --binary ' if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 = v:fname_new if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif let arg3 = v:fname_out if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif let eq = '' if $VIMRUNTIME =~ ' ' if &sh =~ '\<cmd' let cmd = '""' . $VIMRUNTIME . '\diff"' let eq = '"' else let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"' endif else let cmd = $VIMRUNTIME . '\diff' endif silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eqendfunction
"python自动缩进autocmd FileType python setlocal et sta sw=4 sts=4
set nu!set autoindent set ts=4
"括号自动补全inoremap ( ()<LEFT>inoremap [ []<LEFT>inoremap { {}<LEFT>inoremap ' ''<LEFT>inoremap " ""<LEFT>
"F4键跳出括号:imap <F4> <esc>f)a:imap <F4> <esc>f]a
colorscheme desert syntax enable syntax on
set guifont=Consolas:h15
set splitbelow "水平双栏显示在set splitright "水平双栏显示在右
"F5键+Enter一键运行程序map <F5> :call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" if &filetype == 'c' exec "!g++ % -DLOCAL -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -std=c++11 -DLOCAL -Dxiaoai -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "! java %<" elseif &filetype == 'sh' :! bash % elseif &filetype == 'python' exec "! python %" endif endfunc