diff --git a/README.md b/README.md index 709938e..6fe619a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ Features | } +* Insert spaces before closing characters + + input: {|} (press at |) + output: { | } + * Skip closed bracket. input: [] @@ -105,6 +110,13 @@ Options When g:AutoPairsMapCR is on, center current line after return if the line is at the bottom 1/3 of the window. +* g:AutoPairsMapSpace + + Default : 1 + + Map to insert a space after the opening character and before the closing one. + execute 'inoremap =AutoPairsReturn()' + TroubleShooting --------------- The script will remap keys ([{'"}]) , diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 14c075c..76b86c3 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -32,6 +32,10 @@ if !exists('g:AutoPairsMapCR') let g:AutoPairsMapCR = 1 end +if !exists('g:AutoPairsMapSpace') + let g:AutoPairsMapSpace = 1 +end + if !exists('g:AutoPairsCenterLine') let g:AutoPairsCenterLine = 1 end @@ -177,6 +181,17 @@ function! AutoPairsReturn() return "\" endfunction +function! AutoPairsSpace() + let line = getline('.') + let prev_char = line[col('.')-2] + let cmd = '' + let cur_char =line[col('.')-1] + if has_key(g:AutoPairs, prev_char) && g:AutoPairs[prev_char] == cur_char + let cmd = "\\i" + endif + return "\".cmd +endfunction + function! AutoPairsInit() let b:autopairs_loaded = 1 let b:autopairs_enabled = 1 @@ -196,6 +211,10 @@ function! AutoPairsInit() execute 'inoremap AutoPairsReturn()' end + if g:AutoPairsMapSpace + execute 'inoremap AutoPairsSpace()' + end + execute 'inoremap '.g:AutoPairsShortcutFastWrap.' =AutoPairsFastWrap()' execute 'inoremap '.g:AutoPairsShortcutToggle.' AutoPairsToggle()' execute 'noremap '.g:AutoPairsShortcutToggle.' :call AutoPairsToggle()'