From c0593a61c7643046c2a5b6abfc0f2d1a4c90941d Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 12 Feb 2013 14:02:25 +0800 Subject: [PATCH] Delete duplicated pairs in one time. eg ```|``` {{|}} [[|]] --- plugin/auto-pairs.vim | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index de4de2e..e2ce1a1 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -142,7 +142,7 @@ function! AutoPairsInsert(key) let pprev_char = line[col('.')-3] if pprev_char == open && prev_char == open " Double pair found - return a:key."\".repeat(a:key,3)."\\o" + return repeat(a:key, 4) . repeat("\", 3) end end @@ -170,12 +170,35 @@ function! AutoPairsDelete() return "\\" endif + " Delete Repeated Pair eg: '''|''' [[|]] {{|}} + if has_key(b:AutoPairs, prev_char) + let times = 0 + let p = -1 + while get(prev_chars, p, '') == prev_char + let p = p - 1 + let times = times + 1 + endwhile + + let close = b:AutoPairs[prev_char] + let left = repeat(prev_char, times) + let right = repeat(close, times) + + let before = strpart(line, pos-times, times) + let after = strpart(line, pos, times) + if left == before && right == after + return repeat("\\", times) + end + end + + if has_key(b:AutoPairs, prev_char) let close = b:AutoPairs[prev_char] if match(line,'^\s*'.close, col('.')-1) != -1 + " Delete (|___) let space = matchstr(line, '^\s*', col('.')-1) return "\". repeat("\", len(space)+1) elseif match(line, '^\s*$', col('.')-1) != -1 + " Delete (|__\n___) let nline = getline(line('.')+1) if nline =~ '^\s*'.close let space = matchstr(nline, '^\s*')