help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I grep multiple files in Emacs?


From: Fabrice Niessen
Subject: Re: How do I grep multiple files in Emacs?
Date: Fri, 19 Dec 2008 12:00:51 +0100
User-agent: Gnus/5.110009 (No Gnus v0.9) Emacs/23.0.60 (gnu/linux)

deech,

> I frequently have to search multiple files/ buffers for a
> word/phrase. Is there any way to do this in Emacs without
> dropping into the shell?

In my `.emacs' file, I've mapped `C-c 1', `C-c 2' and `C-c 3'
-- I know, this is normally not advised -- to do different
levels of grepping:

    o   C-c 1 searches for a pattern in the file name;

    o   C-c 2 searches for a pattern in the file contents, but
        only displays the file names which are relevant;

    o   C-c 3 searches for a pattern in the file contents, and
        displays all lines which are relevant.

Keys are more or less bound from the less to the most
"verbose"... 1, 2, 3...

--8<---------------cut here---------------start------------->8---
;; search for files with names matching a wild card pattern and Dired the
;; output
(global-set-key [(control c) ?1] 'find-name-dired)

;; search for files with contents matching a wild card pattern and Dired the
;; output
(global-set-key [(control c) ?2] 'find-grep-dired)

;; run grep via find, with user-specified arguments
(global-set-key [(control c) ?3] 'grep-find)

;; ignore `.svn' and `CVS' directories
(setq grep-find-command
      (concat
       "find . \\( -path '*/.svn' -o -path '*/CVS' \\) -prune -o -type f "
              "-print0 | xargs -0 -e grep -i -n -e "))
--8<---------------cut here---------------end--------------->8---

See (info "(emacs)Dired and Find") for further info.

And, if you wish so, you can have a look at the rest of my
`.emacs' file at:

    http://www.mygooglest.com/fni/dot-emacs.html

Best regards,
  Fabrice Niessen

_________________________________________________________________________
Fabrice Niessen
Search the Web with "My Google Search Tools" on http://www.MyGooglest.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]