简体   繁体   English

Emacs搜索并打开多个文件并搜索所有缓冲区

[英]Emacs search and open multiple files and search on all buffers

I'm currently in the beginning of a switching process forwards Emacs. 我目前正处于转换过程的开始,转发Emacs。 However I'm having two basic problems. 但是我有两个基本问题。

  1. How do I search for multiple files recursively from a specific path? 如何从特定路径递归搜索多个文件? I assume I have to use find / grep / dired but I'm not sure. 我假设我必须使用find / grep / dired但我不确定。 For instance I would like to find all *.scala files at path C:/src/xxx .When these files are found I would also like to open them all in the buffer at once. 例如,我想在路径C:/src/xxx找到所有*.scala文件。当找到这些文件时,我还想立即在缓冲区中打开它们。 The only way I'm currently familiar with is Cx Cf . 我目前熟悉的唯一方法是Cx Cf。

  2. When all these files are in the buffer how do I then search across all the buffers, and get some kind of list of the result and/or perhaps able to navigate from result to result? 当所有这些文件都在缓冲区中时,我如何搜索所有缓冲区,并获得某种结果列表和/或可能从结果导航到结果? Saying I would like to find all places with the text case Int => occur. 说我希望找到所有带有文本case Int =>

I concur with phimuemue's answer, but I'll point out Mx rgrep as well, which will run the necessary find/grep in order to present all of the matches without actually opening the files. 我同意phimuemue的回答,但我也会指出Mx rgrep ,它将运行必要的find / grep以便在不实际打开文件的情况下呈现所有匹配。 Selecting a match then opens the relevant file at that line number. 选择匹配然后打开该行号的相关文件。 In some situations, this may be preferable to opening all of those files. 在某些情况下,这可能比打开所有这些文件更可取。

Also see these: 另见这些:

For Part A, you might look here . 对于A部分,您可能会看到这里

For Part B you might have a look at multi-occur-in-matching-buffers , which let's you specify which buffers you want to take (eg all buffers .*.scala to look in all scala files) and what to look for (eg case Int => ). 对于B部分,您可以查看multi-occur-in-matching-buffers ,这可以让您指定要使用的缓冲区(例如,所有缓冲区.*.scala查看所有scala文件)以及要查找的内容(例如, case Int => )。 This gives you a list of all occurences. 这将为您提供所有出现的列表。

You're trying to find all occurrences of "case Int =>" in *.scala files in C:/src 你试图在C:/ src中的* .scala文件中找到所有出现的“case Int =>”

The easiest way (assuming a default Emacs setup) is to use Mx rgrep . 最简单的方法(假设默认的Emacs设置)是使用Mx rgrep It'll ask you for a search-string, file type and directory (in that order, and the prompts are labeled so there's no confusion). 它会询问您搜索字符串,文件类型和目录(按此顺序,并且提示标记为没有混淆)。 Just type in case Int => , *.scala and C:/src/xxx . 只需输入case Int =>*.scalaC:/src/xxx

What you should see is a new buffer with a list of occurrences of "case Int =>" in all .scala files in that directory. 您应该看到的是一个新缓冲区,其中包含该目录中所有.scala文件中出现“case Int =>”的列表。 If you click on an occurrence, Emacs will open that file and navigate to the line that contains it. 如果单击某个事件,Emacs将打开该文件并导航到包含该文件的行。

As a note, if you're trying to do search and replace across multiple files, you can do that using dired options. 请注意,如果您尝试跨多个文件进行搜索和替换,则可以使用dired选项执行此操作。 You can find information on that option here . 您可以在此处找到有关该选项的信息

*For Question A*** *问题A ***

In Icicles , Cx Cf is by default a multi-command . Icicles中Cx Cf默认为多命令 That means that when you complete to a set of file names: 这意味着当您完成一组文件名时:

  • You can act on (eg visit) multiple candidates, selectively (eg C-RET , C-mouse-2 ). 您可以选择性地(例如,访问)多个候选者(例如C-RETC-mouse-2 )。

  • You can act on all files whose names match your current input -- eg, visit them all. 您可以对名称与当前输入匹配的所有文件执行操作 - 例如,全部访问它们。

The same is true for other Icicles file commands, including those that let you match an absolute file name, meaning that your minibuffer patterns can match not just the non-directory part of the file name but directory parts as well. 其他Icicles文件命令也是如此,包括那些允许您匹配绝对文件名的命令,这意味着您的迷你缓冲区模式不仅可以匹配文件名的非目录部分,还可以匹配目录部分。

For example, Cx Cf with a prefix arg matches absolute file names. 例如,带有前缀arg的Cx Cf匹配绝对文件名。 And Mx icicle-locate-file does the same thing for all files under a given directory. 并且Mx icicle-locate-file对给定目录下的所有文件执行相同的操作。

(You can always use a multi-command as an ordinary command: Cx Cf acts normally if you use RET or mouse-2 . If you don't use the extra key bindings to act on multiple files then you'll never know the difference.) (你总是可以使用多命令作为普通命令:如果使用RETmouse-2, Cx Cf会正常工作。如果不使用额外的键绑定来处理多个文件,那么你永远不会知道它们的区别。)

See http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input 请参阅http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input


*For Question B*** *问题B ***

What you want is Icicles search. 你想要的是冰柱搜索。

  • Command icicle-search-file searches all files of a set you specify. 命令icicle-search-file搜索您指定的集合的所有文件。
  • Command icicle-search-buffer searches all buffers of a set you specify. 命令icicle-search-buffer搜索您指定的集合的所有缓冲区。
  • Command icicle-search does both: files with a negative prefix arg, buffers with a non-negative prefix arg. 命令icicle-search同时执行:带有负前缀arg的文件,带有非负前缀arg的缓冲区。

These commands let you specify a regexp to define the search contexts: the parts of the files or buffers that you want to search. 使用这些命令可以指定正则表达式来定义搜索上下文:要搜索的文件或缓冲区的各个部分。 For example, .* means search each line. 例如, .*表示搜索每一行。

After you define the search contexts you type some text in the minibuffer, and it narrows the candidate search contexts to those that match your text. 定义搜索上下文后,在迷你缓冲区中键入一些文本,并将候选搜索上下文缩小为与文本匹配的内容。 You can hit M-SPC to combine multiple such patterns. 你可以点击M-SPC来组合多个这样的模式。

Then you can navigate to the selected search hits: C-RET or C-mouse-2 to visit, or cycle/visit using C-down . 然后您可以导航到所选的搜索命中: C-RETC-mouse-2访问,或使用C-down循环/访问。 You can even sort the matching candidates in various ways, to compare them easily or to change the cycle order. 您甚至可以通过各种方式对匹配的候选项进行排序,轻松比较它们或更改循环顺序。

See http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview

I think you're artificially constraining the answer. 我认为你是人为地限制了答案。 You don't need to load all the files into Emacs in order to find those occurrences. 您不需要将所有文件加载到Emacs中以查找这些事件。 And, once you've found the occurrences of the regexp, you can easily jump to the line in the file with a keystroke. 并且,一旦找到了正则表达式的出现,您就可以通过击键轻松跳转到文件中的行。

My favorite way to do this is to use Mx igrep-find because I like the igrep interface better than Emacs's grep-find . 我最喜欢的方法是使用Mx igrep-find,因为我比Emacs的grep-find更喜欢igrep界面。

You can find the igrep library on emacswiki: igrep.el 您可以在emacswiki: igrep.el上找到igrep库

And the usage would be 用法就是

M-x igrep-find case Int => RET

which would populate a buffer with all the matches, and then (like in occur, grep-find, compilation, etc.) you can use Cx ` or Mx next-error to cycle through the matches. 将填充所有匹配的缓冲区,然后(如发生,grep-find,编译等),您可以使用Cx`Mx next-error循环匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM