From 59ff0db0053ddd54342e89c7c1ecf5c901957710 Mon Sep 17 00:00:00 2001 From: Jakub Fojt Date: Tue, 6 Aug 2019 13:18:58 +0200 Subject: [PATCH] Add strip whitespace and check on write Change-Id: I73ac4260a379c208b1574a934fdbdfb191e5f152 --- .vimrc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.vimrc b/.vimrc index 28ba27a..93598f4 100755 --- a/.vimrc +++ b/.vimrc @@ -16,6 +16,7 @@ if filereadable(expand(vundle_dir) . "/README.md") Plugin 'tpope/vim-fugitive' Plugin 'tpope/vim-surround' Plugin 'ctrlpvim/ctrlp.vim' + Plugin 'rhysd/vim-clang-format' " Plugin 'shougo/neocomplete' Plugin 'godlygeek/tabular' @@ -26,6 +27,8 @@ else command CloneVundle execute "!git clone " . vundle_repo . " " . vundle_dir endif +highlight Search ctermbg=5 + filetype plugin indent on " required syntax on @@ -36,11 +39,30 @@ set expandtab " On pressing tab, insert 4 spaces set mouse=a 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 set nu rnu augroup numbertoggle autocmd! - autocmd BufEnter,FocusGained,InsertLeave * set rnu + autocmd BufEnter,FocusGained,InsertLeave * set rnu autocmd BufLeave,FocusLost,InsertEnter * set nornu augroup END @@ -73,12 +95,12 @@ if has("cscope") "add any database in current dir if filereadable("cscope.out") cs add cscope.out - "else search cscope.out in git folder + "else search cscope.out in git folder else let cscope_file=findfile("cscope.out", git_dir_location) if !empty(cscope_file) && filereadable(cscope_file) exe "cs add" cscope_file git_root_location - endif + endif endif endif