diff --git a/README.md b/README.md index 72bde89..7cdcbf9 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,14 @@ Features input: |[foo, bar()] (press ( at |) output: ([foo, bar()]) +* Quick move char to closed pair + + input: (|){["foo"]} (press at |) + output: ({["foo"]}|) + + input: |[foo, bar()] (press ( at |) + output: ([foo, bar()]|) + * Quick jump to closed pair. input: @@ -249,6 +257,13 @@ Options Work with FlyMode, insert the key at the Fly Mode jumped postion +* g:AutoPairsMoveCharacter + + Default: "()[]{}\"'" + + Map to + move character under the cursor to the pair. + Buffer Level Pairs Setting -------------------------- diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index b4beb21..b2a9af7 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -1,8 +1,8 @@ " Insert or delete brackets, parens, quotes in pairs. " Maintainer: JiangMiao " Contributor: camthompson -" Last Change: 2013-07-13 -" Version: 1.3.2 +" Last Change: 2017-06-17 +" Version: 1.3.3 " Homepage: http://www.vim.org/scripts/script.php?script_id=3599 " Repository: https://github.com/jiangmiao/auto-pairs " License: MIT @@ -49,6 +49,10 @@ if !exists('g:AutoPairsShortcutFastWrap') let g:AutoPairsShortcutFastWrap = '' end +if !exists('g:AutoPairsMoveCharacter') + let g:AutoPairsMoveCharacter = "()[]{}\"'" +end + if !exists('g:AutoPairsShortcutJump') let g:AutoPairsShortcutJump = '' endif @@ -356,6 +360,7 @@ function! AutoPairsMap(key) let escaped_key = substitute(key, "'", "''", 'g') " use expr will cause search() doesn't work execute 'inoremap '.key." =AutoPairsInsert('".escaped_key."')" + endfunction function! AutoPairsToggle() @@ -369,6 +374,12 @@ function! AutoPairsToggle() return '' endfunction +function! AutoPairsMoveCharacter(key) + let c = getline(".")[col(".")-1] + let escaped_key = substitute(a:key, "'", "''", 'g') + return "\\:call search("."'".escaped_key."'".")\a".c."\" +endfunction + function! AutoPairsReturn() if b:autopairs_enabled == 0 return '' @@ -425,13 +436,19 @@ endfunction function! AutoPairsInit() let b:autopairs_loaded = 1 - let b:autopairs_enabled = 1 + if !exists('b:autopairs_enabled') + let b:autopairs_enabled = 1 + end let b:AutoPairsClosedPairs = {} if !exists('b:AutoPairs') let b:AutoPairs = g:AutoPairs end + if !exists('b:AutoPairsMoveCharacter') + let b:AutoPairsMoveCharacter = g:AutoPairsMoveCharacter + end + " buffer level map pairs keys for [open, close] in items(b:AutoPairs) call AutoPairsMap(open) @@ -441,6 +458,11 @@ function! AutoPairsInit() let b:AutoPairsClosedPairs[close] = open endfor + for key in split(b:AutoPairsMoveCharacter, '\s*') + let escaped_key = substitute(key, "'", "''", 'g') + execute 'inoremap =AutoPairsMoveCharacter('".escaped_key."')" + endfor + " Still use level mapping for if g:AutoPairsMapBS " Use instead of for issue #14 sometimes press BS output strange words