Move whitespace stuff to autocommands and add shortcut

pull/2/head
Bodaniel Jeanes 2011-12-27 16:42:45 -06:00
parent ae512ac92c
commit 1fbe2fc111
2 changed files with 20 additions and 14 deletions

View File

@ -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! <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
" Strip trailing whitespace on save
autocmd! BufWritePre * :call <SID>StripTrailingWhitespaces()
" Strip trailing whitespace on command
nmap <Leader>sw :call <SID>StripTrailingWhitespaces()<CR>

View File

@ -118,20 +118,6 @@ syntax on
set number
" Strip trailing whitespace on save
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()
" For when other people use my setup
nmap \ <Leader>