Emacs: Interactively Find and Replace String Patterns on Multiple Files

14 Feb 2010

This is such an invaluable tutorial! I posted it before on twitter but here it is again:
  • Call "dired" or "find-dired" to list files in dir and all subdirs.
  • Mark the files you want. You can mark by regex by typing "%m"
  • Type "Q" to call dired-do-query-replace-regexp.
  • Type your find regex and replace string.
  • For each occurance, type "y" to replace, "n" to skip, "!" for replacing all occurances in current file. Type "Ctrl+g" to abort the whole operation.
  • To do the replacement on all files without further asking, type "Y". To skip all possible replacement on the rest of the current file, type "N". (These are Emacs 23 only)
  • Call "ibuffer" to list all opened files.
  • Type "*u" to mark all unsaved files, type "S" to save all marked files, type "D" to close them all.
There is a much more detailed guide on the page where I got these instructions here:

http://xahlee.org/emacs/find_replace_inter.html