From 1fbe2fc111fec33ce7d9e44f87cc38c76373c019 Mon Sep 17 00:00:00 2001 From: Bodaniel Jeanes Date: Tue, 27 Dec 2011 16:42:45 -0600 Subject: [PATCH] Move whitespace stuff to autocommands and add shortcut --- editors/vim/autocommands.vim | 20 ++++++++++++++++++++ editors/vim/ui.vim | 14 -------------- 2 files changed, 20 insertions(+), 14 deletions(-) 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 \