- 22 December 2013
When working with multiple files, especially for a set of files that contain the same header, we occasionally want to edit the header. This leads to the need to update all other files as well. Fortunately, Emacs has the built in command for interactively find and replace a String pattern in multiple files. Here are the steps on how to quickly find and replace text in multiple files.
- Open the directory that contains all the files web need to find and replace in dired mode.
- Mark the files you want to find the text. Hit
dired-toggle-marks) to select all files in the current folder
dired-do-query-replace-regexp), type in the pattern that you want Emacs to find and the replace string. Hit
- For each occurrence, type
nto skip. Type
Ctrl+gto abort the whole operation.
!to replace all occurrences in current file without asking,
Nto skip all possible replacement for rest of the current file.
- To do the replacement on all files without further asking, type
- Call ibuffer to list all opened files.
* uto mark all unsaved files, type
Sto save all marked files, type
Dto close them all.