support back insert for any situation

This commit is contained in:
jiangfriend@gmail.com 2012-05-14 19:01:22 +08:00
parent eea7b44270
commit 106578d69e

View File

@ -88,6 +88,14 @@ function! AutoPairsInsert(key)
" The key is difference open-pair, then it means only for ) ] } by default
if !has_key(g:AutoPairs, a:key)
let b:autopairs_saved_pair = [a:key, getpos('.')]
" Skip the character if current character is the same as input
if current_char == a:key
return "\<Right>"
end
if !g:AutoPairsFlyMode
" Skip the character if next character is space
if current_char == ' ' && next_char == a:key
return "\<Right>\<Right>"
@ -102,11 +110,7 @@ function! AutoPairsInsert(key)
return "\<ESC>e^a"
endif
endif
" Skip the character if current character is the same as input
if current_char == a:key
return "\<Right>"
end
endif
" Fly Mode, and the key is closed-pairs, search closed-pair and jump
if g:AutoPairsFlyMode && has_key(g:AutoPairsClosedPairs, a:key)
@ -213,7 +217,8 @@ endfunction
function! AutoPairsMap(key)
let escaped_key = substitute(a:key, "'", "''", 'g')
execute 'inoremap <buffer> <silent> <expr>'.a:key." AutoPairsInsert('".escaped_key."')"
" use expr will cause search() doesn't work
execute 'inoremap <buffer> <silent> '.a:key." <C-R>=AutoPairsInsert('".escaped_key."')<CR>"
endfunction
function! AutoPairsToggle()