diff --git a/editors/vim/autocommands.vim b/editors/vim/autocommands.vim index 166051f..db65340 100644 --- a/editors/vim/autocommands.vim +++ b/editors/vim/autocommands.vim @@ -14,3 +14,23 @@ au! FileType scss syntax cluster sassCssAttributes add=@cssColors au! BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby au! BufRead,BufNewFile gitconfig set ft=gitconfig + +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 + +" Strip trailing whitespace on save +autocmd! BufWritePre * :call StripTrailingWhitespaces() + +" Strip trailing whitespace on command +nmap sw :call StripTrailingWhitespaces() + + diff --git a/editors/vim/ui.vim b/editors/vim/ui.vim index b6d94a5..45a0081 100644 --- a/editors/vim/ui.vim +++ b/editors/vim/ui.vim @@ -118,20 +118,6 @@ syntax on set number -" Strip trailing whitespace on save - 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 - autocmd! BufWritePre * :call StripTrailingWhitespaces() - " For when other people use my setup nmap \