1

I want to use Tim Pope's Vim plugin Fugitive's :Ggrep [regex] command to search my codebase, but I would like to open the first match in a new split. How can I do this?

Jordan Eldredge
  • 1,587
  • 1
  • 19
  • 25
  • Will `:split|Ggrep foo` work? or how about doing `s` before the grep? – Peter Rincker Sep 16 '14 at 21:46
  • That doesn't work because Fugitive uses the current buffer's file to determine which git repo it's in. If I open a new split, it has no git repo to reference. – Jordan Eldredge Sep 16 '14 at 21:47
  • 1
    `:split` w/o any arguments or `s` will split the current buffer yielding two windows w/ the same buffer. Therefore `:Ggrep` will work as intended. I have tested both methods out on a repo of mine and it works w/o issue – Peter Rincker Sep 16 '14 at 22:08
  • Doh! You're right. I was thinking `:new` not split. If you write this as an answer, I'll make it as solved. – Jordan Eldredge Sep 16 '14 at 22:48

1 Answers1

4

Split before you Ggrep! Either use :split or <c-w>s and then grep (:grep/:vimgrep/:Ggrep/:Ack/etc).

Usage

:sp|Ggrep foo

and/or

<c-w>s:Ggrep foo

Using the quickfix list

Grep command typically update the quickfix list so it is often handy to have good mappings to :cnext and :cprev. I use ]q and [q respectively which are provided by Tim Pope's unimpaired plugin, along with many other helpful mappings. :copen will open quickfix window if you need to look at the results as a whole.

For more information see:

:h :sp
:h ctrl-w_s
:h :Ggrep
:h quickfix
:h :cnext
:h :cope
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101