From 106578d69e0f48f430ea071f5449b1771cd2e57e Mon Sep 17 00:00:00 2001 From: "jiangfriend@gmail.com" Date: Mon, 14 May 2012 19:01:22 +0800 Subject: [PATCH] support back insert for any situation --- plugin/auto-pairs.vim | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 71db16e..5cb1ee1 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -88,26 +88,30 @@ function! AutoPairsInsert(key) " The key is difference open-pair, then it means only for ) ] } by default if !has_key(g:AutoPairs, a:key) - " Skip the character if next character is space - if current_char == ' ' && next_char == a:key - return "\\" - end - - " Skip the character if closed pair is next character - if current_char == '' - let next_lineno = line('.')+1 - let next_line = getline(nextnonblank(next_lineno)) - let next_char = matchstr(next_line, '\s*\zs.') - if next_char == a:key - return "\e^a" - endif - endif + 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 "\" end + if !g:AutoPairsFlyMode + " Skip the character if next character is space + if current_char == ' ' && next_char == a:key + return "\\" + end + + " Skip the character if closed pair is next character + if current_char == '' + let next_lineno = line('.')+1 + let next_line = getline(nextnonblank(next_lineno)) + let next_char = matchstr(next_line, '\s*\zs.') + if next_char == a:key + return "\e^a" + endif + endif + endif + " Fly Mode, and the key is closed-pairs, search closed-pair and jump if g:AutoPairsFlyMode && has_key(g:AutoPairsClosedPairs, a:key) if search(a:key, 'W') @@ -213,7 +217,8 @@ endfunction function! AutoPairsMap(key) let escaped_key = substitute(a:key, "'", "''", 'g') - execute 'inoremap '.a:key." AutoPairsInsert('".escaped_key."')" + " use expr will cause search() doesn't work + execute 'inoremap '.a:key." =AutoPairsInsert('".escaped_key."')" endfunction function! AutoPairsToggle()