Gabriel Saldaña wrote about using search & replace across files in emacs.
Type:
M-x dired-do-query-replace-regexpto run the find and replace command. It will prompt you first for the text you want to find, then will prompt you with the text you want to replace it with.Then Emacs will start the find and replace operation, and will prompt you on every find if you want to replace the text or skip it. To replace, type “y”, to skip to the next find type “n”. To replace all occurrences without asking, type “!”.
I would note that “!” only replaces matches within the same file; every time you start the query-replace in a new file, you must guide Emacs again. This seems like it’s still quite a bit of work, since you have to hit that bang key 239 times.
Now that you’ve made all these changes, you need to save the files. To avoid saving manually all files, you can open ibuffer
M-x ibufferWhich will list all you opened files (called buffers). Now, like in dired, you need to mark the buffers you want to work with. To mark all unsaved files, type “* u” and then type “S” (that’s shift+s, for the capital letter) to save them.
While I recommend ibuffer, there’s no need to bring it in just to save files. Just hit C-x s (save-some-buffers) and hit “!”. Emacs will save every modified buffer for you.
While I understand that Gabriel’s situation is due to less-than-ideal programmers, I would be remiss if I didn’t say don’t do this. Not the query-replace, which is fine, but the structure of the project in which it is being used. It’s copy and paste code reuse, it doesn’t scale, and it’s a bad idea. Avoid.
Discussion