From 404a121b04d0141f882564f2060c02f578ac00ba Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Tue, 21 Feb 2017 23:53:29 +0800 Subject: [PATCH] Close empty pairs smartly --- plugin/auto-pairs.vim | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index b2a9af7..a1693bb 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -129,12 +129,23 @@ function! AutoPairsInsert(key) return s:Right end - if !g:AutoPairsFlyMode - " Skip the character if next character is space - if current_char == ' ' && next_char == a:key - return s:Right.s:Right - end + " Skip the character if closed pair is next character + if current_char == ' ' && next_char == a:key + " Remove the space we added if the pair is empty + if has_key(b:AutoPairsClosedPairs, a:key) + let end_of_prevchar_index = matchend(before, '\S\ze\s*$') + if end_of_prevchar_index > -1 + let end_of_prevchar = get(prev_chars, end_of_prevchar_index-1, '') + if end_of_prevchar == b:AutoPairsClosedPairs[a:key] + return "\".s:Right + endif + endif + endif + return s:Right.s:Right + endif + + if !g:AutoPairsFlyMode " Skip the character if closed pair is next character if current_char == '' if g:AutoPairsMultilineClose