2

Let's say I want to grep word1 and word2.

If I use the grep command for word1 I get the results in the *grep* buffer. If I then use the grep command for word2 I loose the old results and get the word2 results in a new *grep* buffer.

I want two see the two grep buffers (for example *grep 1* and *grep 2*) at the same time: How to get this?

  • emacswiki.org/emacs/GrepMode mentions grep-a-lot.el, but I have never tried it. – Andrew Swann Oct 22 '16 at 10:24
  • 1
    You may use M-x rename-buffer in *grep* buffer to rename it. – Evgeny Panasyuk Oct 22 '16 at 10:39
  • 1
    @EvgenyPanasyuk But then you need to move to another buffer before running grep again, or it will reuse the renamed buffer (emacs 24.5.1) – JeanPierre Oct 22 '16 at 14:18
  • @JeanPierre Yes, I also noticed this. – Evgeny Panasyuk Oct 22 '16 at 15:39
1

You can do this easily if you use library Grep+ (grep+.el).

Use + in your first *grep* buffer, followed by g. The + renames the first *grep* buffer by appending <N> (N=2,3,...) to it, and it opens a new buffer named *grep*. The g in that buffer then launches a new grep command there.

C-h k + tells you this:

+ runs the command grepp-new-grep-buffer, which is an interactive compiled Lisp function in grep+.el.

It is bound to +, menu-bar grep grepp-new-grep-buffer.

(grepp-new-grep-buffer)

Rename current grep buffer and switch to new buffer *grep*. Current buffer must be a grep buffer. It is renamed to *grep*<N>.

0

You can save the word1 result in some temporary file then do another grep for word2.

  • 1
    Have you tried that? I found that if I stay in this saved buffer, it will be reused for the next grep. – JeanPierre Oct 22 '16 at 14:14
  • @JeanPierre If you go back to the directory you want to grep, you don't get this problem. – rl1 Oct 22 '16 at 16:53
0

You can pipe your grep's with a double pipe ('||'). This might be a alternative.

 M-x grep 
 grep -nrH 'word1' ||  grep -nrH 'word2'

The results of word1 will appear and afterwards the results of word2. BUT, both in the same grep-buffer...

  • That doesn't sound like what OP is requesting. I think the request is to have two separate grep buffers, one for word1 matches and one for word2 matches, not a single grep buffer for matches of both word1 and word2. – Drew Apr 2 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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