Find and replace all text (strings) interactivelly in Emacs
This how to search/find/query and replace a string recursively in a directory in interctive manner.
Method 1
M-x find-dired-name: Choose a subdirectory you want to search in.t: “toggle mark” for all files you findQ: “Query-replace” interactivelyC-x s !to save all files changed at once, but there are an option to save one by one
Credit to Stackoverflow thread
Method 2
C-x d: for Emacs’ built-in file manager dired- Mark some files for the operation with
m(Unmark withu). M-x(also known asAlt-x)dired-do-query-replace-regexpor simply pressQ.- Interactive prompt appears in minibuffer (ie. the bottom-line of the screen)
- Enter query term (a string like “foo”)
- Enter replace term (like “bar”)
- Results will appear in a new window, then press
?for available options.
Credit to Xah-Lee blog.