Add strip whitespace and check on write

Change-Id: I73ac4260a379c208b1574a934fdbdfb191e5f152
This commit is contained in:
Jakub Fojt
2019-08-06 13:18:58 +02:00
parent d959aa232c
commit 59ff0db005

28
.vimrc
View File

@@ -16,6 +16,7 @@ if filereadable(expand(vundle_dir) . "/README.md")
Plugin 'tpope/vim-fugitive' Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround' Plugin 'tpope/vim-surround'
Plugin 'ctrlpvim/ctrlp.vim' Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'rhysd/vim-clang-format'
" Plugin 'shougo/neocomplete' " Plugin 'shougo/neocomplete'
Plugin 'godlygeek/tabular' Plugin 'godlygeek/tabular'
@@ -26,6 +27,8 @@ else
command CloneVundle execute "!git clone " . vundle_repo . " " . vundle_dir command CloneVundle execute "!git clone " . vundle_repo . " " . vundle_dir
endif endif
highlight Search ctermbg=5
filetype plugin indent on " required filetype plugin indent on " required
syntax on syntax on
@@ -36,11 +39,30 @@ set expandtab " On pressing tab, insert 4 spaces
set mouse=a set mouse=a
set hlsearch set hlsearch
" Warn for trailing whitespace. Search with wrap (w) do not move cursor (n)
function! WhitespaceWarn()
echohl WarningMsg
echo 'Found whitespace.'
echohl None
echon ' Type :TrailWhitespace to remove it'
endfunction
function! StripTrailingWhitespace()
" Save cursor position
let l:save = winsaveview()
" Remove trailing whitespace
%s/\s\+$//e
" Move cursor to original position
call winrestview(l:save)
echo "Stripped trailing whitespace"
endfunction
autocmd BufWritePost * if search('\s\+$', 'wn') | call WhitespaceWarn() | endif
command TrailWhitespace call StripTrailingWhitespace()
" Hybrid line numbers on active buffer " Hybrid line numbers on active buffer
set nu rnu set nu rnu
augroup numbertoggle augroup numbertoggle
autocmd! autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set rnu autocmd BufEnter,FocusGained,InsertLeave * set rnu
autocmd BufLeave,FocusLost,InsertEnter * set nornu autocmd BufLeave,FocusLost,InsertEnter * set nornu
augroup END augroup END
@@ -73,12 +95,12 @@ if has("cscope")
"add any database in current dir "add any database in current dir
if filereadable("cscope.out") if filereadable("cscope.out")
cs add cscope.out cs add cscope.out
"else search cscope.out in git folder "else search cscope.out in git folder
else else
let cscope_file=findfile("cscope.out", git_dir_location) let cscope_file=findfile("cscope.out", git_dir_location)
if !empty(cscope_file) && filereadable(cscope_file) if !empty(cscope_file) && filereadable(cscope_file)
exe "cs add" cscope_file git_root_location exe "cs add" cscope_file git_root_location
endif endif
endif endif
endif endif