4

I am trying to quickly search and replace in multiple files using dired. The steps I follow are from this question (Chris Conway's and Frank Henard's answers), I am pretty sure the instructions are correct since it seems like I am the only person having this problem.

To simplify the problem, the steps I am doing are as follows:

  • Open a folder in dired
  • Mark a file with m
  • Q to search and replace in the marked file, this command will ask for two arguments, in the search query argument I type div, and in the replacement query argument I type foo (to replace div with foo).

After I do these simple steps, the search throws no results, the buffer says:

No matches for: div

I know plenty divs are spreaded all over the file. Perhaps I am not entering the arguments in the correct format, I tryed many things, like enclosing the string in quotes or double quotes, and running emacs with the -q argument in the shell to disable my dotfile. The instructions looked pretty simple, I don't know what I am doing wrong.

Emacs version: 25.1.1

5
  • What OS are you on? I believe this uses grep, so it may be an issue with what grep executable it is finding or what args are being passed. Also, try to reproduce this after starting with emacs with -Q (ie with the default settings, no local config.)
    – glucas
    Commented Feb 3, 2017 at 23:11
  • Fedora 25. Yes, I ran emacs with -q and -Q, the problem persists. M-x rgrep works fine, but dired's Q option doesn't.
    – mikl
    Commented Feb 3, 2017 at 23:17
  • Are your values for grep-find-ignored-files and grep-find-ignored-directories a factor? (Although they also affect rgrep.) FYI the implementation for the Q binding is completely new in Emacs 25. 24.5 runs tags-query-replace whereas 25.1 uses the new xref-collect-matches and xref-query-replace-in-results.
    – phils
    Commented Feb 3, 2017 at 23:50
  • @Drew I think you should add this as an answer instead of a comment so it can be marked as the proper answer.
    – Fabman
    Commented Aug 9, 2017 at 10:54
  • @Fabman: OK, I added it as an answer.
    – Drew
    Commented Aug 9, 2017 at 14:04

1 Answer 1

7

As @phils said in a comment, Emacs 25.1 no longer uses dired-do-query-replace-regexp for Q. It uses dired-do-find-regexp-and-replace for Q.

(It shouldn't, IMHO, but it does.)

Try M-x dired-do-query-replace-regexp. If that works, you can just bind it to Q to have Q act the same as it used to.

4
  • Do you know why dired-do-find-regexp-and-replace fails to find matches for regexps that work just fine with dired-do-query-replace-regexp? More than that, I'm just replacing string literals, e.g. TEST_STRING -> teststring, and it's failing to find matches.
    – Andy
    Commented Aug 14, 2017 at 17:05
  • 1
    @Andy: No, sorry; I don't know. I haven't investigated d-d-f-r-a-r. (I don't even use it, myself.) But if you have a concrete query that you think should succeed but which fails, then consider filing a bug: M-x report-emacs-bug. (For the example you mention, are you taking care of case-sensitivity? Could that be the problem?)
    – Drew
    Commented Aug 14, 2017 at 18:17
  • Finally I can search and replace using regexps that contain newlines again. Thank you!
    – taranaki
    Commented Sep 23, 2019 at 21:27
  • @taranaki: Consider filing a bug report / enhancement request for the xref stuff, if it doesn't let you do that: M-x report-emacs-bug.
    – Drew
    Commented Sep 23, 2019 at 23:23

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.