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?

- 371
- 1
- 11
1 Answers
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 ()
(interactive)
(let ((find-grep-options "-q -i"))
(call-interactively #'find-grep-dired)))
(define-key global-map (kbd "C-c z") #'find-grep-dired-case-insensitive)
Footnote:
[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".

- 29,717
- 3
- 27
- 44
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 '22 at 13:29-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 '22 at 13:38grep
option so you'll see it withman grep
from a shell prompt. The documentation string offind-grep-options
also shows this. Customize the variable to add-i
to it (as I mention in the answer). – NickD Feb 20 '22 at 13:46-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 forAbcd
it finds it. But when I search for-i abcd
it does not find it. What am I doing wrong? – zeynel Feb 20 '22 at 14:04-q
and-i
– zeynel Feb 20 '22 at 14:11-i abcd
"? Are you typing the-
at the regexp prompt? If so, don't do that: just typeabcd
. – NickD Feb 20 '22 at 14:45regexp conforming to grep syntax
? In the prompt I enter only regex, correct? – zeynel Feb 20 '22 at 15:02.el
files for the elisp sources). My guess is that you're using a Debian-packaged emacs and need toapt-get install emacs-el
(or something similar). – phils Feb 20 '22 at 21:00apt-get install emacs-common-non-dfsg
(or look up the correct name for that package for your particular OS/version). – phils Feb 22 '22 at 01:20