From c2f0eef628ac1bc3c8ebb42a927c65d96699cf2c Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Sat, 19 Jan 2019 11:37:41 +0800 Subject: [PATCH] Prevent jumping if open key equals close key, fixes #231 --- README.md | 27 ++++++++------------------- plugin/auto-pairs.vim | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 4c03984..68643ed 100644 --- a/README.md +++ b/README.md @@ -308,27 +308,16 @@ Multibyte Pairs The text after // in close pair is modifiers n - do not map the first charactor of closed pair to close key - s - do not jump through multi line + m - close key jumps through multi line + s - close key jumps only in the same line - pair: "'''":"'''" - input: - ''' - | - ''' (press ') - output: - ''' - - '''| + by default if open key equals close key the multi line is turn off - pair: "'''":"'''//s" - input: - ''' - | - ''' (press ') - output: - ''' - '|' - ''' + "" ? jumps only in the same line + "//m" force ? jumping through multi line + "" ? will jump through multi line + "//s" force ? only jumping in the same line + "//n" do not jump totally 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 88a2264..ee63471 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -393,6 +393,9 @@ func! AutoPairsSpace() let [before, after, ig] = s:getline() for [open, close, opt] in b:AutoPairsList + if close == '' + continue + end if before =~ '\V'.open.'\v$' && after =~ '^\V'.close return "\\".s:Left end @@ -444,20 +447,29 @@ func! AutoPairsInit() let b:AutoPairsList = [] " buffer level map pairs keys + " 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 for [open, close] in items(b:AutoPairs) - let o = open[len(open)-1] - let m = matchlist(close, '\v(.*)//(.*)$') + let o = open[-1:-1] + let c = close[0] let opt = {'mapclose': 1, 'multiline':1} + if o == c + let opt['multiline'] = 0 + end + let m = matchlist(close, '\v(.*)//(.*)$') if len(m) > 0 if m[2] =~ 'n' let opt['mapclose'] = 0 end + if m[2] =~ 'm' + let opt['multiline'] = 1 + end if m[2] =~ 's' let opt['multiline'] = 0 end let close = m[1] end - let c = close[0] call AutoPairsMap(o) if o != c && c != '' && opt['mapclose'] call AutoPairsMap(c)