diff --git a/README.markdown b/README.markdown index d2a5c29..9df7a01 100644 --- a/README.markdown +++ b/README.markdown @@ -77,6 +77,12 @@ support: Only the opening brackets—`[`, `{`, and `(`—add a space. Use a closing bracket, or the `b` (`(`) and `B` (`{`) aliases. +Two new global variables have been added to toggle whether spaces are added +to the opening and closing brackets, respectively + + let g:surround_insert_space_left = 1 " left: opening brackets + let g:surround_insert_space_right = 0 " right: closing brackets + ## Contributing See the contribution guidelines for diff --git a/plugin/surround.vim b/plugin/surround.vim index 8a4016e..44664a6 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -8,6 +8,9 @@ if exists("g:loaded_surround") || &cp || v:version < 700 endif let g:loaded_surround = 1 +let g:insert_space_left = get(g:, 'surround_insert_space_left', 1) +let g:insert_space_right = get(g:, 'surround_insert_space_right', 0) + " Input functions {{{1 function! s:getchar() @@ -237,7 +240,14 @@ function! s:wrap(string,char,type,removed,special) let before = '('.fnc.' ' let after = ')' elseif idx >= 0 - let spc = (idx % 3) == 1 ? " " : "" + let pos = idx % 3 + let spc = "" + if g:insert_space_left && pos == 1 " left brackets + let spc = " " + endif + if g:insert_space_right && pos == 2 " right brackets + let spc = " " + endif let idx = idx / 3 * 3 let before = strpart(pairs,idx+1,1) . spc let after = spc . strpart(pairs,idx+2,1)