1ehkva
Last Updated: February 25, 2016
·
524
· endel
Profile 2015 2

Remove white-spaces, please!

I like to navigate through code using paragraph motion ("{" and "}" keys). But if you leave white-spaces between every single empty line of code, it's impossible to do that.

So, please. Remove white-spaces for the sake of your teammates.

Add to your ~/.vimrc:

function! <SID>RemoveWhitespaces()
  let l = line(".")
  let c = col(".")
  execute '%s/\s\+$//e'
  call cursor(l, c)
endfunction

" Remove white-spaces on write
autocmd BufWritePre * :call <SID>RemoveWhitespaces()

" Shift+Space will remove white-spaces immediately
nnoremap <silent> <S-Space> :call <SID>RemoveWhitespaces()<CR>
Say Thanks
Respond

1 Response
Add your response

2134
Visual2015

How about the simpler:

:%s/^\s+$//

over 1 year ago ·
Filed Under