Skip to content

Instantly share code, notes, and snippets.

@kumabotz
Created July 8, 2014 08:16
Show Gist options
  • Save kumabotz/70ad1f4c32c500a6167d to your computer and use it in GitHub Desktop.
Save kumabotz/70ad1f4c32c500a6167d to your computer and use it in GitHub Desktop.
if has("autocmd")
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
endif
function! <SID>StripTrailingWhitespaces()
" preparation: save last search, and cursor position
let _s=@/
let l = line(".")
let c = col(".")
" do the business
%s/\s\+$//e
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment