From 65a9f452f2238ca6c89576a7cdd305d78fda28e5 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Wed, 27 Feb 2019 16:34:50 +0800 Subject: [PATCH] Obsolete wild close key by default, add custom close key, improve #242 --- README.md | 10 ++-------- plugin/auto-pairs.vim | 12 +++++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d467cf9..8d079ba 100644 --- a/README.md +++ b/README.md @@ -248,14 +248,6 @@ Options Map to move character under the cursor to the pair. -* g:AutoPairsWildClosedPair - - Default: ']' - - Jump over following closed pair - for pair {'begin': 'end//n]'}, e is not mapped, use wild closed pair ] to jump over 'end' - use to back insert ] after jumping - Buffer Level Pairs Setting -------------------------- @@ -313,6 +305,7 @@ Multibyte Pairs n - do not map the first charactor of closed pair to close key m - close key jumps through multi line s - close key jumps only in the same line + k[KEY] - map the close key to [KEY] by default if open key equals close key the multi line is turn off @@ -321,6 +314,7 @@ Multibyte Pairs "" ? will jump through multi line "//s" force ? only jumping in the same line "//n" do not jump totally + "//k]" use key ] to jump through ?> for 'begin' 'end' pair, e is a charactor, if map e to jump will be annoy, so use modifier 'n' to skip key map diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index e630454..66a0c6c 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -25,7 +25,7 @@ func! AutoPairsDefaultPairs() let allPairs = { \ 'vim': {'\v^\s*\zs"': ''}, \ 'rust': {'\w\zs<': '>', '&\zs''': ''}, - \ 'php': {'//n', '//n'} + \ 'php': {'//k]', '//k]'} \ } for [filetype, pairs] in items(allPairs) if &filetype == filetype @@ -52,7 +52,7 @@ if !exists('g:AutoPairsMapCR') end if !exists('g:AutoPairsWildClosedPair') - let g:AutoPairsWildClosedPair = ']' + let g:AutoPairsWildClosedPair = '' end if !exists('g:AutoPairsMapSpace') @@ -263,7 +263,7 @@ func! AutoPairsInsert(key) if close == '' continue end - if a:key == g:AutoPairsWildClosedPair || opt['mapclose'] && close[0] == a:key + if a:key == g:AutoPairsWildClosedPair || opt['mapclose'] && opt['key'] == a:key " the close pair is in the same line let m = matchstr(afterline, '^\v\s*\V'.close) if m != '' @@ -494,6 +494,7 @@ func! AutoPairsInit() let o = open[-1:-1] let c = close[0] let opt = {'mapclose': 1, 'multiline':1} + let opt['key'] = c if o == c let opt['multiline'] = 0 end @@ -508,6 +509,11 @@ func! AutoPairsInit() if m[2] =~ 's' let opt['multiline'] = 0 end + let ks = matchlist(m[2], '\vk(.)') + if len(ks) > 0 + let opt['key'] = ks[1] + let c = opt['key'] + end let close = m[1] end call AutoPairsMap(o)