使用 Emacs 递归查找和替换尚未打开的文本文件 [英] Using Emacs to recursively find and replace in text files not already open
问题描述
作为这个问题的后续,它试图找出如何做这样的事情,这应该很容易,这尤其让我无法习惯使用 Emacs,而是启动我已经熟悉的编辑器.我在编辑多个文件时经常使用这里的示例.
As a follow-up to this question, it's trying to find out how to do something like this which should be easy, that especially stops me from getting more used to using Emacs and instead starting up the editor I'm already familiar with. I use the example here fairly often in editing multiple files.
在 Ultraedit 中,我先按 Alt+s 然后按 p 来显示一个带有选项的对话框:查找(包括在多行中使用正则表达式)、替换为、在文件/类型中、目录、匹配大小写、匹配整个单词仅,列出更改的文件和搜索子目录.通常我会先用鼠标点击拖动选择我要替换的文本.
In Ultraedit I'd do Alt+s then p to display a dialog box with the options: Find (includes using regular expressions across multiple lines), Replace with, In Files/Types, Directory, Match Case, Match Whole Word Only, List Changed Files and Search Sub Directories. Usually I'll first use the mouse to click-drag select the text that I want to replace.
仅使用 Emacs 本身(在 Windows XP 上),不调用任何外部实用程序,如何将 *.c
和 *.h中的所有 foo
bar 替换为 bar
baz
某个文件夹中的文件及其下的所有文件夹.也许 Emacs 不是最好的工具,但如何用最少的命令轻松完成?
Using only Emacs itself (on Windows XP), without calling any external utility, how to replace all foo
bar with bar
baz in *.c
and *.h
files in some folder and all folders beneath it. Maybe Emacs is not the best tool to do this with, but how can it be done easily with a minimal command?
推荐答案
M-x find-name-dired
:系统将提示您输入根目录和文件名模式.- 按
t
以切换标记";对于找到的所有文件. - 按
Q
进行Query-Replace in Files...":系统将提示您输入查询/替换正则表达式. - 与
query-replace-regexp
一样继续:SPACE
替换并移动到下一个匹配,n
跳过匹配等. - 按
C-x s
保存缓冲区.(然后您可以按y
表示是,n
表示否,或!
表示是所有)
M-x find-name-dired
: you will be prompted for a root directory and a filename pattern.- Press
t
to "toggle mark" for all files found. - Press
Q
for "Query-Replace in Files...": you will be prompted for query/substitution regexps. - Proceed as with
query-replace-regexp
:SPACE
to replace and move to next match,n
to skip a match, etc. - Press
C-x s
to save buffers. (You can then pressy
for yes,n
for no, or!
for yes for all)
这篇关于使用 Emacs 递归查找和替换尚未打开的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!