1
0
mirror of https://github.com/gryf/.vim.git synced 2025-12-17 19:40:29 +01:00

Added possibilty to turn off removing trailing spaces

This commit is contained in:
2014-07-28 20:39:08 +02:00
parent 15369edeee
commit 7521d31361

43
.vimrc
View File

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