From 4c4f66d9ac1d08def63e827662f346c29327c5c5 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Mon, 4 Nov 2019 17:27:26 -0500 Subject: [PATCH] vim: use tpope's :Ggrep over home-rolled :GitGrep, update mappings My GitGrep served me very well over the years, but tpope added :Ggrep to fugitive, and, well, his is of course more robust and more clever! This commit removes my home-rolled solution in favor of the fugitive plugin. Additionally, two mapping changes: 1) inoremap to save in the undo chain 2) Remove arrow key mappings -- these were throwing other vimmer's off when they used my setup! --- vim/autoload/vimrc.vim | 51 --------------------------------------------------- vim/vimrc | 11 ++++------- 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index 4dfcab9..9d1223b 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -1,8 +1,6 @@ " autoload/vimrc.vim -- functions to be called in vimrc " " See `:h autoload-functions` for explanation of autoloading and performance - - function! vimrc#ToggleColorColumn() abort if &colorcolumn == "" set colorcolumn=80 @@ -11,55 +9,6 @@ function! vimrc#ToggleColorColumn() abort endif endfunction -" Searches all of project for word under cursor -function! vimrc#GitGrep(word) abort - if s:InGitRepo() - let raw = system('git grep -n ' . a:word) - let matches = split(raw, '\n') - let qfitems = [] - for m in matches - let items = split(m, ':') - " Rare case that we match a binary file - if len(items) < 3 - continue - endif - let d = { - \'filename': items[0], - \'lnum': items[1], - \'text': join(items[2:], '') - \} - - let qfitems += [d] - endfor - call setqflist(qfitems, 'r') - else - call utils#warn("called GitGrepWordUnderCursor outside of git repo") - endif -endfunction - -function! vimrc#GitGrepWordUnderCursor() abort - let word = substitute(expand(''), '#', '\\#', 'g') - call vimrc#GitGrep(word) -endfunction - -function! s:InGitRepo() abort - if has('win64') || has('win32') - let fsep = '\' - else - let fsep = '/' - endif - let dir_list = split(getcwd(), fsep) - let running_path = '' - for dir in dir_list - let running_path = join([running_path, dir], fsep) - let f = running_path . fsep . '.git' - if filereadable(f) || isdirectory(f) - return 1 - endif - endfor - return 0 -endfunction - function! vimrc#SetPasteAndPasteFromClipboard() abort set paste normal! "+p diff --git a/vim/vimrc b/vim/vimrc index 0d43935..8f589c3 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -164,18 +164,12 @@ nnoremap C vimrc#ToggleColorColumn() nnoremap 2 :setlocal softtabstop=2 shiftwidth=2 nnoremap 4 :setlocal softtabstop=4 shiftwidth=4 -" Faster file navigation -nnoremap :cprev -nnoremap :cnext -nnoremap :prev -nnoremap :next - " Clear that highlight! nnoremap :nohlsearch " Get greppin quick! --> search word under cursor (escape # for VimL autoload) nnoremap g :exe "grep " . substitute(expand(''), '#', '\\#', 'g') -nnoremap G :call vimrc#GitGrepWordUnderCursor():copen +nnoremap G :Ggrep! :copen " Toggle whitespace nnoremap w :set list! @@ -185,6 +179,9 @@ nnoremap y gg"+yG " Edit vimrc nnoremap V :edit $HOME/.vim/vimrc + +" From defaults.vim: breaks the undo chain so we can undo +inoremap u " }}} " COMMANDS {{{ -- libgit2 0.28.4