Skip to content

Instantly share code, notes, and snippets.

@armeo
Created January 31, 2014 04:35
Show Gist options
  • Save armeo/8726671 to your computer and use it in GitHub Desktop.
Save armeo/8726671 to your computer and use it in GitHub Desktop.
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
nnoremap <silent> <F5> :call <SID>StripTrailingWhitespaces()<CR>
autocmd BufWritePre *.py,*.php,*.js,*.css,*.feature,*.java,*.rb :call <SID>StripTrailingWhitespaces()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment