I am getting \'trailing whitespace\' errors trying to commit some files in git.
I want to remove these trailing whitespace characters automatically right before I sa
Compilation of above plus saving cursor position:
fun! StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
keepp %s/\s\+$//e
call cursor(l, c)
endfun
autocmd FileType c,cpp,java,php,ruby,python autocmd BufWritePre :call StripTrailingWhitespaces()
If you want to apply this on save to any file, leave out the second autocmd and use a wildcard *:
autocmd BufWritePre * :call StripTrailingWhitespaces()