Skip to content

Instantly share code, notes, and snippets.

@yubrew
Created September 19, 2013 18:02
Show Gist options
  • Save yubrew/6627430 to your computer and use it in GitHub Desktop.
Save yubrew/6627430 to your computer and use it in GitHub Desktop.
strip whitespace. put in .vimrc
" Remove trailing whitespace upon save
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 *.rb,*.rake,*.coffee,*.slim :call <SID>StripTrailingWhitespaces()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment