diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 7eead0b..d8de91d 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -1,7 +1,7 @@ " Language: JavaScript " Maintainer: JiangMiao " Last Change: 2011-05-22 -" Version: 1.0 +" Version: 1.0.1 " Repository: https://github.com/jiangmiao/auto-pairs " " Insert or delete brackets, parens, quotes in pairs. @@ -23,6 +23,9 @@ if !exists('g:AutoPairs') let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"'} end +let g:AutoPairsClosedPairs = {} + + function! AutoPairsInsert(key) let line = getline('.') @@ -81,6 +84,17 @@ function! AutoPairsJump() call search('[{("\[\]'')}]','W') endfunction +function! AutoPairsExtend() + let line = getline('.') + let current_char = line[col('.')-1] + + if has_key(g:AutoPairsClosedPairs, current_char) + return "\lxh:call AutoPairsJump(line('.'))\pi" + end + + return '' +endfunction + function! AutoPairsMap(key) execute 'inoremap '.a:key.' =AutoPairsInsert("\'.a:key.'")' endfunction @@ -91,6 +105,7 @@ function! AutoPairsInit() if open != close call AutoPairsMap(close) end + let g:AutoPairsClosedPairs[close] = 1 endfor execute 'inoremap =AutoPairsDelete()' @@ -99,6 +114,7 @@ function! AutoPairsInit() execute 'inoremap :call AutoPairsJump()a' execute 'inoremap ' execute 'inoremap ' + execute 'inoremap =AutoPairsExtend()' end endfunction