Skip to content

Add two global variables to toggle whether spaces are added inside brackets, respectively #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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)

" 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