Created
April 4, 2017 02:00
-
-
Save carld/44a67739ac4d2d2820af51b2475eeb13 to your computer and use it in GitHub Desktop.
Emacs wgrep renaming in many files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/37654293/replace-text-in-all-files-within-a-directory-subdirectories-in-emacs/37685982#37685982 | |
I generally do this the way @lawlist suggests. Here it is step-by-step: | |
Install wgrep from Melpa or some other way. I recommend also wgrep-ag and ag if you use The Silver Searcher. | |
Use M-x rgrep (or M-x ag) to search the files and get a list of lines to potentially change. | |
In the *grep* buffer, run M-x wgrep-change-to-wgrep-mode. I bind this to C-x C-q in grep-mode-map. | |
Use query-replace-regexp (C-M-%), or do any other editing in the *grep* buffer. | |
Save the *grep* buffer with C-x C-s. Use C-c C-k to abort. The changes exist only in the *grep* buffer until you save it. You can re-enable wgrep mode any number of times. | |
All of the files in the grep search now have open buffers with modifications to them if you saved the *grep* buffer. Do C-x s to save all of them to disk. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment