Skip to content

Commit

Permalink
Add vim setting to not leave whitespace after backslash
Browse files Browse the repository at this point in the history
Should avoid problem in #207,
but should it be the default?
  • Loading branch information
AndrewRadev committed Nov 5, 2023
1 parent 5396244 commit 172febb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
7 changes: 6 additions & 1 deletion autoload/sj/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ function! sj#vim#Split()
if sj#BlankString(new_line)
return 0
else
let new_line = "\n\\ ".sj#Trim(new_line)
if sj#settings#Read('vim_split_whitespace_after_backslash')
let new_line = "\n\\ ".sj#Trim(new_line)
else
let new_line = "\n\\".sj#Trim(new_line)
endif

call sj#ReplaceMotion('vg_', new_line)
call sj#Keeppatterns('s/\s\+$//e')

Expand Down
1 change: 1 addition & 0 deletions plugin/splitjoin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let g:splitjoin_default_settings = {
\ 'html_attribute_bracket_on_new_line': 0,
\ 'java_argument_split_first_newline': 0,
\ 'java_argument_split_last_newline': 0,
\ 'vim_split_whitespace_after_backslash': 1,
\ }

if !exists('g:splitjoin_join_mapping')
Expand Down
46 changes: 46 additions & 0 deletions spec/plugin/vim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
vim.set 'shiftwidth', 2
end

after :each do
vim.command('silent! unlet g:splitjoin_vim_split_whitespace_after_backslash')
end

specify ":if commands" do
contents = <<~EOF
if condition == 1
Expand All @@ -23,4 +27,46 @@
split
assert_file_contents contents
end

specify "backslashes" do
set_file_contents <<~EOF
let foo = 2 + 2
EOF

vim.search('+')
split

assert_file_contents <<~EOF
let foo = 2
\\ + 2
EOF

join

assert_file_contents <<~EOF
let foo = 2 + 2
EOF
end

specify "backslashes without a space" do
vim.command('let g:splitjoin_vim_split_whitespace_after_backslash = 0')

set_file_contents <<~EOF
let foo = 2 + 2
EOF

vim.search('+')
split

assert_file_contents <<~EOF
let foo = 2
\\+ 2
EOF

join

assert_file_contents <<~EOF
let foo = 2 + 2
EOF
end
end

0 comments on commit 172febb

Please sign in to comment.