Last Updated: February 25, 2016
·
730
· endel

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>

1 Response
Add your response

How about the simpler:

:%s/^\s+$//

over 1 year ago ·