不解释了,把下面代码贴到.vimrc文件中就行了,然后,重新打开vim,写一个函数试试,我感觉还不错的…
- :inoremap <S-ENTER> <c-r>=SkipPair()<CR>
- :inoremap <S-SPACE> <ESC>la
- :inoremap <C-ENTER> <ESC>A;<CR>
- :inoremap ( ()<ESC>i
- :inoremap ) <c-r>=ClosePair(‘)’)<CR>
- :inoremap { <c-r>=ClsoeBrace()<CR>
- :inoremap } <c-r>=ClosePair(‘}’)<CR>
- :inoremap [ []<ESC>i
- :inoremap ] <c-r>=ClosePair(‘]’)<CR>
- :inoremap ;; <ESC>A;<CR>
- function ClosePair(char)
- if getline(‘.’)[col(‘.’) – 1] == a:char
- return "\<Right>"
- else
- return a:char
- endif
- endf
- function Semicolon()
- "echo getline(‘.’)[col(‘.’)]
- if getline(‘.’)[col(‘.’)] == ‘)’
- return "<ESC>A;"
- elseif getline(‘.’)[col(‘.’)] == ‘}’
- return "\<ESC>A;"
- elseif getline(‘.’)[col(‘.’)] == ‘]’
- return "\<ESC>A;"
- else
- return ";"
- endif
- endf
- function SkipPair()
- if getline(‘.’)[col(‘.’) – 1] == ‘)’
- return "\<ESC>o"
- else
- normal j
- let curline = line(‘.’)
- let nxtline = curline
- while curline == nxtline
- if getline(‘.’)[col(‘.’) – 1] == ‘}’
- normal j
- let nxtline = nxtline + 1
- let curline = line(‘.’)
- continue
- else
- return "\<ESC>i"
- endif
-
- endwhile
- return "\<ESC>o"
- endif
- endf
- function ClsoeBrace()
- if getline(‘.’)[col(‘.’) – 2] == ‘=’
- return "{}\<ESC>i"
- elseif getline(‘.’)[col(‘.’) – 3] == ‘=’
- return "{}\<ESC>i"
- elseif getline(‘.’)[col(‘.’) – 1] == ‘{‘
- return "{}\<ESC>i"
- elseif getline(‘.’)[col(‘.’) – 2] == ‘{‘
- return "{}\<ESC>i"
- elseif getline(‘.’)[col(‘.’) – 2] == ‘,’
- return "{}\<ESC>i"
- elseif getline(‘.’)[col(‘.’) – 3] == ‘,’
- return "{}\<ESC>i"
- else
- return "{\<ENTER>}\<ESC>O"
- endif
- endf
|
:inoremap <S-ENTER> <c-r>=SkipPair()<CR> :inoremap <S-SPACE> <ESC>la :inoremap <C-ENTER> <ESC>A;<CR> :inoremap ( ()<ESC>i :inoremap ) <c-r>=ClosePair(')')<CR> :inoremap { <c-r>=ClsoeBrace()<CR> :inoremap } <c-r>=ClosePair('}')<CR> :inoremap [ []<ESC>i :inoremap ] <c-r>=ClosePair(']')<CR> :inoremap ;; <ESC>A;<CR> function ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf function Semicolon() "echo getline('.')[col('.')] if getline('.')[col('.')] == ')' return "<ESC>A;" elseif getline('.')[col('.')] == '}' return "\<ESC>A;" elseif getline('.')[col('.')] == ']' return "\<ESC>A;" else return ";" endif endf function SkipPair() if getline('.')[col('.') - 1] == ')' return "\<ESC>o" else normal j let curline = line('.') let nxtline = curline while curline == nxtline if getline('.')[col('.') - 1] == '}' normal j let nxtline = nxtline + 1 let curline = line('.') continue else return "\<ESC>i" endif endwhile return "\<ESC>o" endif endf function ClsoeBrace() if getline('.')[col('.') - 2] == '=' return "{}\<ESC>i" elseif getline('.')[col('.') - 3] == '=' return "{}\<ESC>i" elseif getline('.')[col('.') - 1] == '{' return "{}\<ESC>i" elseif getline('.')[col('.') - 2] == '{' return "{}\<ESC>i" elseif getline('.')[col('.') - 2] == ',' return "{}\<ESC>i" elseif getline('.')[col('.') - 3] == ',' return "{}\<ESC>i" else return "{\<ENTER>}\<ESC>O" endif endf |