From 85e2c73830b6bb01ce7fc3a926d2b25836a253eb Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 8 Apr 2020 02:36:17 -0400 Subject: [PATCH] Favor :Ggrep over :Git grep I'm starting to think :Git grep shouldn't be special cased. Occasionally it is desirable to see grep results without clobbering the quickfix list. Reserve -O/--open-files-in-pager to opt into quickfix behavior, as this fits well with Fugitive's use of a temp buffer as the Git pager. --- README.markdown | 2 +- autoload/fugitive.vim | 3 +++ plugin/fugitive.vim | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index d44b870..dd3bcc9 100644 --- a/README.markdown +++ b/README.markdown @@ -21,7 +21,6 @@ improvements: enter on a line to view the commit where the line changed, or `g?` to see other available maps. Omit the filename argument and the currently edited file will be blamed in a vertical, scroll-bound split. -* `:Git grep` loads matches into the quickfix list, just like `:grep`. * `:Git mergetool` and `:Git difftool` load their changesets into the quickfix list. * Called with no arguments, `:Git` opens a summary window with dirty files and @@ -48,6 +47,7 @@ Additional commands are provided for higher level operations: * `:Gwrite` writes to both the work tree and index versions of a file, making it like `git add` when called from a work tree file and like `git checkout` when called from the index or a blob in history. +* `:Ggrep` is `:grep` for `git grep`. `:Glgrep` is `:lgrep` for the same. * `:GMove` does a `git mv` on the current file and changes the buffer name to match. `:GRename` does the same with a destination filename relative to the current file's directory. diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 91a4a9c..53f999a 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -4136,6 +4136,9 @@ function! s:GrepSubcommand(line1, line2, range, bang, mods, options) abort endif let tree = s:Tree(dir) let args = a:options.args + if get(args, 0, '') =~# '^-O\|--open-files-in-pager$' + let args = args[1:-1] + endif let name_only = s:HasOpt(args, '-l', '--files-with-matches', '--name-only', '-L', '--files-without-match') let title = [listnr < 0 ? ':Ggrep' : ':Glgrep'] + args if listnr > 0 diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 73e93d8..21577de 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -437,9 +437,9 @@ unlet s:cmd exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Gcd exe fugitive#Cd(, 0)" exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Glcd exe fugitive#Cd(, 1)" -exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Ggrep exe fugitive#Command(, , +"", 0, "", "grep " . )' -exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Gcgrep exe fugitive#Command(, , +"", 0, "", "grep " . )' -exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Glgrep exe fugitive#Command(0, > 0 ? : 0, +"", 0, "", "grep " . )' +exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Ggrep exe fugitive#Command(, , +"", 0, "", "grep -O " . )' +exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Gcgrep exe fugitive#Command(, , +"", 0, "", "grep -O " . )' +exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Glgrep exe fugitive#Command(0, > 0 ? : 0, +"", 0, "", "grep -O " . )' exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Glog :exe fugitive#LogCommand(,,+"",0,"",, "")' exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Gclog :exe fugitive#LogCommand(,,+"",0,"",, "c")'