Within helm I'd like to find all of the files that have the content 'foo' and 'bar', even if 'foo' and 'bar' are on different lines.

  • I don't think you can do that with a single grep command. I would do that with a command like comm -12 <(grep -lr "foo" . ) <(grep -lr "bar" . ), which you can enter in M-x grep, but the filenames wont be "click"-able. Commented Jan 27, 2016 at 17:23
  • That is a good point about grep. I've rephrased the question to better indicate what I really want.
    – razeh
    Commented Jan 27, 2016 at 17:26
  • Have you tried helm-projectile-grep? See the heading "Search in project" over here: tuhdo.github.io/helm-projectile.html
    – Brian Z
    Commented Jan 27, 2016 at 17:43
  • Grep v3.1 supports multi-line pattern.
    – chen bin
    Commented Mar 19, 2018 at 6:15

2 Answers 2


You can use helm-ff-do-grep inside helm-find-files session.

  • Inside helm-find-files session. You can invoke helm-ff-run-grep with C-s and C-u as prefix argument. Then choose where/what to search then it prompt you a pattern to search.

helm-ff-do-grep use ack or grep as backend. see https://tuhdo.github.io/helm-intro.html#orgheadline11

Or You can use helm-org-rifle

In contrast with org-occur and similar commands, helm-org-rifle is entry-based (i.e. a heading and all of its contents, not including subheadings), while org-occur is line-based. So org-occur will show you entire lines that contain matching words, without any reference to the heading the line is under, while helm-org-rifle will show the heading of the entry that matches, followed by context around each matching word in the entry. In other words, helm-org-rifle is sort of like Google, while org-occur is sort of like grep.


If you are not limited to Helm, you can do this easily using Icicles.

C-x C-f C-M-j foo S-SPC C-M-j bar


  • C-x C-f is the command for finding a file (icicle-file). It uses multi-completion input (like the Helm command you are used to, I presume). This means that you can match either file name or file content, or both. In this case, you apparently do not care about the file names, so you match only the content (see next).

  • C-M-j is (by default) the key that separates file-name pattern from file-content pattern. You can use any key you like for this -- it's customizable (but there is a good reason for this odd-seeming default value). You use this key immediately, because there is no file-name pattern to match in your case. You use it to go on to specifying a file-content pattern.

  • foo is the first pattern that you want the file content to match.

  • S-SPC is the key to narrow to the current set of completion candidates, in this case, all files that contain a match for foo (which in this case is a literal pattern, so all files that contain foo). You can think of this key as "locking-in" a set of matches so that they become the new domain to match against. (Again, the key that does this is only S-SPC by default; you can customize it to be any other key.)

  • C-M-j again, to skip a file-name pattern and provide another file-content pattern.

  • bar is the second pattern that you want the file content to match.

What you see now is the set of files you are after. You can choose one to visit, or you can visit all of them at once (using C-!).

Here is another example you can follow, with explanations:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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