Remove trailing whitespace from files on save

pull/2/head
Bodaniel Jeanes 2011-02-08 23:43:56 +10:00
parent 544a1db252
commit 0892bc5f35
1 changed files with 15 additions and 0 deletions

View File

@ -247,6 +247,21 @@ set directory=~/.vim/backup
" better way to run this? " better way to run this?
let ignorethisvar = system("mkdir -p ~/.vim/backup") let ignorethisvar = system("mkdir -p ~/.vim/backup")
" 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()
" Align cucumber tables " Align cucumber tables
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a