作为这个问题的后续,它试图找出如何做这样的事情,这应该很容易,这尤其阻止我更习惯于使用Emacs,而是启动我已经熟悉的编辑器。在编辑多个文件时,我经常使用这个示例。
在Ultraedit中,我用Alt+s然后p来显示一个带有选项的对话框:查找(包括跨多行使用正则表达式),替换,在文件/类型中,目录,匹配大小写,仅匹配整个单词,列出更改的文件和搜索子目录。通常我会先用鼠标点击-拖动选择我想要替换的文本。
只使用Emacs本身(在Windows XP上),不调用任何外部实用程序,如何替换所有的foo\nbar与bar\nbaz在*.c和*.h文件中的一些文件夹和它下面的所有文件夹。也许Emacs并不是最好的工具,但是如何用最少的命令就能轻松完成呢?
M-x find-name-dired RET
it may take some time for all the files to appear in the list, scroll to bottom (M->) until "find finished" appears to make sure they all have loaded
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 or y to replace and move to next match, n to skip a match, etc.
Type ! to replace all occurrences in current file without asking, N to skip all possible replacement for rest of the current file. (N is emacs 23+ only)
To do the replacement on all files without further asking, type Y.
Call “ibuffer” (C-x C-b if bound to ibuffer, or M-x ibuffer RET) to list all opened files.
Type * u to mark all unsaved files, type S to save all marked files
* * RET to unmark all marks, or type D to close all marked files
这个答案结合了这个答案、这个网站和我自己的笔记。使用Emacs 23+。