如何“M-x替换字符串”跨越emacs的所有缓冲区? [英] How do I "M-x replace-string" across all buffers in emacs?
本文介绍了如何“M-x替换字符串”跨越emacs的所有缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
Mx ibuffer
RET t U
$ b $但是你可能想要比这更有限制,因为如果它不能做一个替换,它会中止 - 例如遇到包含匹配文件名的只读dired缓冲区。
Ch m 在ibuffer中阅读模式帮助,并学习如何轻松地标记您感兴趣的缓冲区。
编辑:非正则表达式版本 ibuffer-do-replace-regexp
可以通过修改原始定义轻松地写入:
;;定义ibuffer-do-replace-string
(define-ibuffer-op replace-string(from-str to-str)
在标记缓冲区中执行replace-string。
(:interactive
(let from(from-str(read-from-minibufferReplace string:))
(to-str(from-minibuffer
with:)))))
(从str到str的列表)
:opstring替换为
:complex t
: p:也许)
(save-window-excursion
(switch-to-buffer buf)
(save-excursion
(goto-char(point-min))
(let((case-fold-search ibuffer-case-fold-search))
(while(从-ni t搜索转发)
(替换匹配to-str nil t) )))
t))
How do I "M-x replace-string" across all buffers in emacs?
解决方案
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))
这篇关于如何“M-x替换字符串”跨越emacs的所有缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文