Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Suppose I have a file formatted like this:

file1:123
file2:4444
some/other/file:2233

This represents the search results from a grep (i.e. 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, ...).

share|improve this question
add comment

3 Answers

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.

share|improve this answer
add comment

In vim command mode:

For internal grep,

:vimgrep pattern-to-search files
:copen

see :help vimgrep for help.

For external grep,

:grep pattern-to-search files
:copen

see :help grep for help.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.