projectile-greps are probably the commands that I use the most. However, with some very large projects I am frequently interested in grepping only one subdirectory of the project. For my greps I usually use helm-projectile-agbut it recursively greps in project's root.

The closest think that I have found is helm-do-grep-ag but it works on default-directory. To achieve the effect on grepping specific directory I first have to set that directory as default-directory.

How do you achieve grepping in project's subdirectory? Is there some parameter that I am terribly missing somewhere?

  • At minimum, M-x rgrep will let you do this. (or M-x lgrep if you don't want recursive searching). I'd be surprised if other facilities don't have that as an option, though. Have you tried using a prefix argument?
    – phils
    May 2, 2019 at 0:01

2 Answers 2


For grep itself, M-x rgrep (recursive from specified directory), and M-x lgrep (specified directory only) let you do this.


To achieve what you described I use: helm-ag package. helm-do-ag interactive function will prompt you for the directory where to search. Just bind it to your preferred key shortcut.

  • How to setq the directory or directories where to search? I would like to use helm-do-grep-ag so it always searches within specific folders. Is this possible? Thanks! Jan 15, 2021 at 10:00
  • I have a small function to do this: github.com/daviderestivo/galactic-emacs/blob/… Jan 20, 2021 at 5:49
  • Thanks, @Davide Restivo. I'm a newbie in elisp. If I wanted to change org directory for.a specific path, how would I replace that in your function? I really don't understand it :/ Thanks for all the help! Jan 20, 2021 at 10:06
  • 1
    @EmmanuelGoldstein: here a simplified version that searches in your Document folder and add a keybinding to <f5>. I hope this helps :) Jan 23, 2021 at 7:42
  • Thanks a lot. It works. I replaced helm-do-ag with helm-ag, and it's very useful as it works the same as helm-do-ag, but it prompts for a second search within those found items. Jan 23, 2021 at 11:24

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.