How do I "M-x replace-string" across all buffers in emacs?
When you want to replace every instance of a given string, you can use a simple command that tells Emacs to do just that. Type ESC x replace-string RETURN, then type the search string and press RETURN. Now type the replacement string and press RETURN again.
M-x kill-matching-buffers. Offer to kill all buffers matching a regular expression. C-x k ( kill-buffer ) kills one buffer, whose name you specify in the minibuffer. The default, used if you type just RET in the minibuffer, is to kill the current buffer.
M-x ibuffer
RET t U
But you'll probably want to be a bit more restrictive than that, because it will abort if it can't do a replacement -- e.g. encounters a read-only dired buffer containing a matching filename.
C-hm within ibuffer to read the mode help, and learn how to easily mark just the buffers you're interested in.
Edit: a non-regexp version of ibuffer-do-replace-regexp
can easily be written by modifying the original definition:
;; defines ibuffer-do-replace-string (define-ibuffer-op replace-string (from-str to-str) "Perform a `replace-string' in marked buffers." (:interactive (let* ((from-str (read-from-minibuffer "Replace string: ")) (to-str (read-from-minibuffer (concat "Replace " from-str " with: ")))) (list from-str to-str)) :opstring "replaced in" :complex t :modifier-p :maybe) (save-window-excursion (switch-to-buffer buf) (save-excursion (goto-char (point-min)) (let ((case-fold-search ibuffer-case-fold-search)) (while (search-forward from-str nil t) (replace-match to-str nil t)))) t))
There are a bunch of different choices, it kind of depends on how you want to do it.
Check out the Emacs Wiki for SearchBuffers. Of interest would be moccur-edit and icicles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With