如何跨emacs中的所有缓冲区"Mx replace-string"?

Dav*_*own 23 emacs

如何跨emacs中的所有缓冲区"Mx replace-string"?

phi*_*ils 21

M-x ibuffer RET t U

但是你可能希望比这更具限制性,因为如果它不能进行替换它会中止 - 例如遇到包含匹配文件名的只读dired缓冲区.

C-hm 在ibuffer中阅读模式帮助,并学习如何轻松地标记您感兴趣的缓冲区.

编辑:ibuffer-do-replace-regexp通过修改原始定义可以轻松编写非正则表达式版本:

;; 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))
Run Code Online (Sandbox Code Playgroud)

  • 此外,`Mx ibuffer RET t Q`将以交互方式执行相同操作,让您有机会确认每次更换. (5认同)