I’m trying to do a case insensitive search with M-x find-grep-dired. When I enter M-x find-grep-dired and hit ENTER and enter the directory name I get the prompt find-grep (grep regexp):. I understand this as “enter grep and then regexp”. So, for grep I enter -i for case insensitive search, and for regexp I enter the search word. But this does not work. What am I doing wrong?

enter image description here

1 Answer 1


The second prompt is asking you for just a "grep regexp", i.e. a regexp conforming to grep syntax [1]. If you look at the implementation of find-grep-dired (C-h f find-grep-dired and click on the file link), you'll see that it uses find-grep-options, so you can add -i to the value of that variable. You can do that by asking for help on the variable (C-h v find-grep-options) and then clicking on the Customize link.

EDIT: if you don't want to change the value of find-grep-dired permanently, you can use the standard lisp facility of binding a variable temporarily with let:

(let ((find-grep-options "-q -i"))
   (call-interactively #'find-grep-dired))

That's a very general mechanism that is worth remembering and getting familiar with.

And you can of course package that in a command and bind it to a key if you want:

(defun find-grep-dired-case-insensitive ()
   (let ((find-grep-options "-q -i"))
      (call-interactively #'find-grep-dired)))

(define-key global-map (kbd "C-c z") #'find-grep-dired-case-insensitive)


[1] There are other regexp syntaxes: e.g. perl regexp syntax is different in many ways from that of (basic) grep; GNU grep can use an extended syntax if you give it a -E option; Emacs has its own syntax for regexps. They are all similar in many ways, but differ in others. That's why the documentation of the function says to use a "grep regexp".

  • Thanks. I don’t see a file link to click. But I did, C-h v find-grep-options and on that screen I clicked “customize” and I got a screen with “Find Grep Options: -q". Do I need to change -q to -i? What does -q mean? I searched for “grep options -q” but nothing relevant resulted.
    – zeynel
    Feb 20, 2022 at 13:29
  • I found that -q means "Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages option."
    – zeynel
    Feb 20, 2022 at 13:38
  • Correct: it's a grep option so you'll see it with man grep from a shell prompt. The documentation string of find-grep-options also shows this. Customize the variable to add -i to it (as I mention in the answer).
    – NickD
    Feb 20, 2022 at 13:46
  • Ok. I added -i so now I have -q and -i, and saved and restarted emacs. But it does not work. The text I search has a capital letter "Abcd", so when I search for Abcd it finds it. But when I search for -i abcd it does not find it. What am I doing wrong?
    – zeynel
    Feb 20, 2022 at 14:04
  • 1
    "I don’t see a file link to click." means that you have an incomplete installation of Emacs (you are missing the .el files for the elisp sources). My guess is that you're using a Debian-packaged emacs and need to apt-get install emacs-el (or something similar).
    – phils
    Feb 20, 2022 at 21:00

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.