標籤:
不廢話,直接上代碼:
1 """"""""""""""""""""""""""""""""""""""""""" 2 "自動執行個體括弧 3 """"""""""""""""""""""""""""""""""""""""""" 4 ""inoremap ( ()<ESC>i 5 inoremap ( <c-r>=OpenPair(‘(‘,‘)‘)<CR> 6 inoremap ) <c-r>=ClosePair(‘)‘)<CR> 7 inoremap { {}<ESC>i 8 inoremap } <c-r>=ClosePair(‘}‘)<CR> 9 inoremap [ []<ESC>i10 inoremap ] <c-r>=ClosePair(‘]‘)<CR>11 inoremap " <c-r>=QuoteDelim(‘"‘)<CR>12 inoremap ‘ <c-r>=QuoteDelim("‘")<CR>13 14 function! OpenPair(char1,char2)15 let line = getline(‘.‘)16 let col = col(‘.‘)17 if col(‘$‘) == col18 return a:char1 . a:char2. "\<Left>"19 else20 return a:char1 21 endif22 endfunction23 24 function! ClosePair(char)25 if getline(‘.‘)[col(‘.‘) - 1] == a:char26 return "\<Right>"27 else28 return a:char29 endif30 endfunction31 32 function! QuoteDelim(char)33 let line = getline(‘.‘)34 let col = col(‘.‘)35 if line[col - 2] == "\\"36 "Inserting a quoted quotation mark into the string37 return a:char38 elseif line[col - 1] == a:char39 "Escaping out of the string40 return "\<Right>"41 else42 "Starting a string43 return a:char.a:char."\<Esc>i"44 endif45 endf
我的vim 自動執行個體括弧函數