使用Emacs递归查找和替换尚未打开的文本文件 [英] Using Emacs to recursively find and replace in text files not already open

查看:150
本文介绍了使用Emacs递归查找和替换尚未打开的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为此问题,它试图找出如何做这样的事情,这应该是容易的,特别是阻止我越来越习惯使用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,然后显示一个对话框,其中包含:Find(includes使用正则表达式跨多行),替换为,文件/类型,目录,匹配大小写,匹配全字,列出已更改的文件和搜索子目录。通常我会先使用鼠标点击拖动选择要替换的文本。

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上),而不调用任何外部实用程序,如何用 *中的bar\\\
baz替换所有foo\
bar。c
*。h 文件在一些文件夹和它下面的所有文件夹。可能Emacs不是最好的工具,但是如何用最小的命令轻松完成?

Using only Emacs itself (on Windows XP), without calling any external utility, how to replace all foo\nbar with bar\nbaz 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?

推荐答案


  1. Mx find-name-dired :将提示您输入根目录和文件名模式。

  2. t 为所有找到的文件切换标记。

  3. Q 对于在文件中的查询替换...:将提示您进行查询/替换正则表达式。

  4. 继续执行 query-replace-regexp SPACE 替换并移动到下一个匹配项, n 跳过匹配等。 / li>
  1. M-x find-name-dired: you will be prompted for a root directory and a filename pattern.
  2. Press t to "toggle mark" for all files found.
  3. Press Q for "Query-Replace in Files...": you will be prompted for query/substitution regexps.
  4. Proceed as with query-replace-regexp: SPACE to replace and move to next match, n to skip a match, etc.

这篇关于使用Emacs递归查找和替换尚未打开的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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