Search code examples
vimvim-fugitive

How can I run Fugitive's :Ggrep in a new split?


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?


Solution

  • 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