Skip to content

Instantly share code, notes, and snippets.

@ampvchen
Created March 21, 2014 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ampvchen/9692232 to your computer and use it in GitHub Desktop.
Save ampvchen/9692232 to your computer and use it in GitHub Desktop.
Vim Remove Trailing Whitespaces
" Strip trailing whitespace
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
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment