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.
You can use
helm-find-filessession. You can invoke
helm-ff-run-grepwith 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-fis 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-jis (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.
foois the first pattern that you want the file content to match.
S-SPCis 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-SPCby default; you can customize it to be any other key.)
C-M-jagain, to skip a file-name pattern and provide another file-content pattern.
baris 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
Here is another example you can follow, with explanations: