Suppose I have a file formatted like this:


This represents the search results from a command grep (i.e. the format file:line-number).

I'd like to have a vim plugin which would allow me quickly browse through those hits. It would display a two-pane window (split horizontally) with the top pane showing the hits and the bottom pane showing currently selected hit. Changing the selection in the top pane displays the specified file at the indicated line number in the bottom pane.

Anyone run across something like this? I'd even consider a non-vim solution (emacs/dedicated program, ...).

3 Answers 3


In Emacs, run open the grep results and run M-x grep-mode.

If you saved the grep results in a file that isn't in the directory you ran grep in, you'll need to run M-x cd to change to the proper directory.

The grep output needs to contain a : after the line number, i.e. you need to have file_name:line_number:text, where the text is optional but the second : isn't. You could change this by tuning grep-regexp-alist.

Of course, if you run M-x grep, all of that works automatically.


In vim command mode:

For internal grep,

:vimgrep pattern-to-search files

see :help vimgrep for help.

For external grep,

:grep pattern-to-search files

see :help grep for help.


Emacs support this through the rgrep and lgrep commands (type M-x rgrep or M-x lgrep, where M-x is Emacs' notation for Alt+x), which are included in Emacs at least since version 22. The command rgrep runs a recursive grep search, whereas lgrep is limited to files in a single directory.

They display grep results in a separate pane, one per line; you can navigate results by:

  • either clicking on a result line (will open the relevant file in another window), or

  • repeatedly pressing C-x ` (Ctrl+x followed by the back-tick key): each time you hit this key combination, the current pane will display the next grep hit on the list.emphasized text

More information in the GNU Emacs manual, chapter "Grep searching"

Note: In Emacs' terminology, a pane is called a window, and a window is called a frame.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .