1

How do I replace string across all open buffers in emacs? I found this on internet but option 'Y' to change all buffers in one shot doesn't work and I need to change one buffer for time with '!' option.

;; Query Replace in open Buffers
(defun query-replace-in-open-buffers (arg1 arg2)
  "query-replace in open files"
  (interactive "sQuery Replace in open Buffers: \nsquery with: ")
  (mapcar
   (lambda (x)
     (find-file x)
     (save-excursion
       (beginning-of-buffer)
       (query-replace arg1 arg2)))
   (delq
    nil
    (mapcar
     (lambda (x)
       (buffer-file-name x))
     (buffer-list)))))
Mario Giovinazzo
  • 431
  • 2
  • 12

2 Answers2

1

Easy, just use multi-occur-in-matching-buffers and then press e for occur-edit-mode. Then query-replace I guess. Finish off with C-c C-c. And don't forget to save all changed buffers.

abo-abo
  • 20,038
  • 3
  • 50
  • 71
0

With Icicles, Use C-u C-c ' in Icicle mode. That searches a subset you choose of the open buffers (or all of them).

See also https://stackoverflow.com/a/7137348/729907.

Community
  • 1
  • 1
Drew
  • 29,895
  • 7
  • 74
  • 104