Skip to content

Commit

Permalink
Delete duplicated pairs in one time.
Browse files Browse the repository at this point in the history
eg ```|``` {{|}} [[|]]
  • Loading branch information
jiangmiao committed Feb 12, 2013
1 parent f11f3e5 commit c0593a6
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion plugin/auto-pairs.vim
Expand Up @@ -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."\<CR>".repeat(a:key,3)."\<Up>\<ESC>o"
return repeat(a:key, 4) . repeat("\<LEFT>", 3)
end
end

Expand Down Expand Up @@ -170,12 +170,35 @@ function! AutoPairsDelete()
return "\<BS>\<DEL>"
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("\<BS>\<DEL>", 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 "\<BS>". repeat("\<DEL>", 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*')
Expand Down

0 comments on commit c0593a6

Please sign in to comment.