我如何“M-x 替换字符串"?跨 emacs 中的所有缓冲区? [英] How do I "M-x replace-string" across all buffers in emacs?

查看:19
本文介绍了我如何“M-x 替换字符串"?跨 emacs 中的所有缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 emacs 中的所有缓冲区中M-x 替换字符串"?

How do I "M-x replace-string" across all buffers in emacs?

推荐答案

Mx 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 在 ibuffer 中阅读模式帮助,并学习如何轻松标记您感兴趣的缓冲区.

C-hm within ibuffer to read the mode help, and learn how to easily mark just the buffers you're interested in.

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

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))

这篇关于我如何“M-x 替换字符串"?跨 emacs 中的所有缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆