gistfile1.vim This file contains hidden or 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 Show hidden characters " Strip trailing whitespace function ! 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 " Run before every buffer write autocmd BufWritePre * : call StripTrailingWhitespaces ()