Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion plugin/surround.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +11 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should be s:insert_space_right. No point in defining a second global config variable.


" Input functions {{{1

function! s:getchar()
Expand Down Expand Up @@ -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)
Expand Down