Created
September 8, 2011 19:05
-
-
Save glennr/1204354 to your computer and use it in GitHub Desktop.
Uber-Glory for VIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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