vim自动补全括号、引号等

将下列代码复制到.vimrc便可以自动补全

inoremap ( ()i
inoremap [ []i
inoremap { {}O
autocmd Syntax html,vim inoremap < >i| inoremap > =ClosePair('>')
inoremap ) =ClosePair(')')
inoremap ] =ClosePair(']')
inoremap } =CloseBracket()
inoremap " =QuoteDelim('"')
inoremap ' =QuoteDelim("'")

function ClosePair(char)
 if getline('.')[col('.') - 1] == a:char
 return "\"
 else
 return a:char
 endif
endf

function CloseBracket()
 if match(getline(line('.') + 1), '\s*}') < 0
 return "\}"
 else
 return "\j0f}a"
 endif
endf

function QuoteDelim(char)
 let line = getline('.')
 let col = col('.')
 if line[col - 2] == "\\"
 return a:char
 elseif line[col - 1] == a:char
 return "\"
 else
 return a:char.a:char."\i"
 endif
endf

你可能感兴趣的:(vim自动补全括号、引号等)