diff --git a/.vimrc b/.vimrc index 508be5c..e87806b 100644 --- a/.vimrc +++ b/.vimrc @@ -22,7 +22,7 @@ NeoBundle "gryf/zoom.vim" NeoBundle "hallison/vim-markdown" NeoBundle "honza/vim-snippets" NeoBundle "http://repo.or.cz/r/vcscommand.git" -NeoBundle "https://code.google.com/p/vimwiki/" +NeoBundle "vimwiki/vimwiki" NeoBundle "kazuyukitanimura/jsbeautify" NeoBundle "kevinw/pyflakes-vim" NeoBundle "kien/ctrlp.vim" @@ -131,6 +131,10 @@ set noswapfile "in case they are needed, store swapfiles in tmp "set dir=~/tmp/ +" Strip trailing whitespace option +let stripTrailingWhitespace = 1 + + " TOhtml options let html_number_lines = 1 let html_use_css = 1 @@ -143,12 +147,7 @@ let g:browser = 'firefox' "COMMON: specific vim behaviour {{{ " "remove all trailing whitespace for specified files before write -autocmd BufWritePre *.py :call StripTrailingWhitespaces() -autocmd BufWritePre *.rst :call StripTrailingWhitespaces() -autocmd BufWritePre *.wiki :call StripTrailingWhitespaces() -autocmd BufWritePre *.js :call StripTrailingWhitespaces() -autocmd BufWritePre *.css :call StripTrailingWhitespaces() -autocmd BufWritePre *.xml :call StripTrailingWhitespaces() +autocmd BufWritePre * :call StripTrailingWhitespaces(0) "set correct filetype for tmux autocmd BufRead *.tmux.conf set filetype=tmux autocmd BufRead *.mako set filetype=mako @@ -295,7 +294,7 @@ map :QFix map :LWin "remove trailing whitespaces -nnoremap e :StripTrailingWhitespaces +nnoremap e :StripTrailingWhitespaces! " copy current buffer filename (full path) nmap ,cn :silent call CopyFileName(1) @@ -350,18 +349,24 @@ function Make() endfunction " Remove 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) +function StripTrailingWhitespaces(force) + if a:force != 1 && g:stripTrailingWhitespace == 0 + return + endif + + if a:force == 1 || &ft =~ 'python\|rst\|wiki\|javascript\|css\|html\|xml' + " 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) + endif endfunction -command StripTrailingWhitespaces call StripTrailingWhitespaces() +command -bang StripTrailingWhitespaces call StripTrailingWhitespaces(0) function CopyFileName(full) if a:full