2

There is a folder with many sub-folders, files and I would like to search for a given piece of text in all of these files with Emacs on a Windows 10 machine. (I know about M-x grep, but it does not work in Windows environment.)

Is there any way to start such recursive search from within Emacs on Windows 10 without installing additional software or extensions?

(The question marked as a "possible duplicate" is different. My question is about searching in files' contents. The another question is about searching for files.)

  • 2
    M-x grep works just fine in Windows if you install grep. In general, Emacs works best with certain Unix-y command line tools installed as well. If you have no issue installing Emacs, I can't imagine why you'd have an issue with installing the additional software that Emacs wants to be able to use. – phils Jan 25 '17 at 11:33
  • Agreed. The emacs experience on windows is improved dramatically with something like msys2. – InHarmsWay Jan 25 '17 at 12:20
  • If you only need to know if a regular expression is present in files, then you can use the % g command in dired. – DoMiNeLa10 Jan 25 '17 at 12:34
  • I don't have time to check now, but this smells like a duplicate. I'm pretty sure there are other questions about searching a set of files etc. – Drew Jan 25 '17 at 15:31
4

You can use Windows' builtin findstr command with M-x rgrep:

(when (eq system-type 'windows-nt)
  (with-eval-after-load 'grep
    ;; findstr can handle the basic find|grep use case
    (grep-apply-setting 'grep-find-template
                        "findstr /S /N /D:. /C:<R> <F>")
    (setq find-name-arg nil)))

It's not as versatile as grep, but it's fine for searching for fixed strings. Also note that Emacs sometimes suggests globs like *.[ch] but you need to use *.c *.h instead (use C-q SPC to enter the space).

3

you can try the xah-find package. https://github.com/xahlee/xah-find

it is pure elisp, and designed just for emacs without external grep tools.

0

You could try Emacs Helm which is available to install from MELPA Stable. The Helm framework allows you to easily and intuitively work with files, directories and buffers. Moreover, it provide simple access to common Helm commands such as grep, find, locate, etc...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.