Skip to content

Instantly share code, notes, and snippets.

@jbowes
Created March 8, 2013 20:43
Show Gist options
  • Save jbowes/5119703 to your computer and use it in GitHub Desktop.
Save jbowes/5119703 to your computer and use it in GitHub Desktop.
function! StripTrailingWhitespace()
" 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