Skip to content

Instantly share code, notes, and snippets.

@nyarly
Created January 17, 2015 00:53
Show Gist options
  • Save nyarly/25c682aa0902a735e978 to your computer and use it in GitHub Desktop.
Save nyarly/25c682aa0902a735e978 to your computer and use it in GitHub Desktop.
function! TrimWhite()
let view = winsaveview()
silent! %s/\s\+$//e
silent! g/^[\n\s]*\%$/d
call winrestview(view)
endfunction
command! TrimWhite :call TrimWhite()
if !exists("trimwhite_au")
let trimwhite_au = 1
autocmd BufWritePre *.erl,*.rb,*.haml,*.js,*.rake,Rakefile* :call TrimWhite()
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment