简体   繁体   English

Emacs-多行搜索

[英]Emacs - multiline search

Is there a module to do multiline search in Emacs ? 在Emacs中是否有模块可以进行多行搜索?

I have used grep , pt and now ag , and they are great. 我用过grepptag ,它们很棒。 But sometimes when exploring a codebase you search for things that are on multiple lines (and therefore get nothing), but reducing the search to fewer words yields a lot of results. 但是有时在探索代码库时,您会搜索多行内容(因此一无所获),但是将搜索减少到更少的单词会产生很多结果。

Is there a way to get multiline search in Emacs in a whole project ? 有没有办法在整个项目的Emacs中进行多行搜索?

Of course there is. 当然有。 There are multiple ways. 有多种方法。

You don't say what kind of search you are trying to do: single file? 您没有说要尝试哪种搜索:单个文件? multiple buffers? 多个缓冲区? regexp? 正则表达式? Do you need a fixed list of search hits or do you want incremental search? 您需要固定的搜索命中列表还是想要增量搜索?


Here's one simple answer: 这是一个简单的答案:

  1. In a Dired buffer, mark some files you want to search, then hit A . 在Dired缓冲区中,标记一些要搜索的文件,然后按A

  2. Type a regexp to match. 键入一个正则表达式进行匹配。 Use Cq Cj to enter a newline char to match. 使用Cq Cj输入要匹配的换行符。 Hit RET to enter the regexp. 点击RET输入正则表达式。

That searches through the marked files, stopping at each search hit in turn. 它将搜索标记的文件,并在每次搜索命中时停止。 Use M-, to go to the next hit, etc. 使用M-,键转到下一个匹配项, M-,

For example, to search for doc strings of variable definitions, search with this regexp or similar: 例如,要搜索变量定义的文档字符串,请使用此正则表达式或类似内容进行搜索:

Search marked files (regexp): (defvar.*
.*"Non-nil

There's a newline char after the first .* , which you enter using Cq Cj . 在第一个.*之后有一个换行符,您可以使用Cq Cj输入。


There are lots of other ways to search in Emacs. 在Emacs中还有许多其他搜索方式。 The best place to start is the Search and Replace category of Emacs Wiki. 最好的起点是Emacs Wiki的“ 搜索和替换”类别。 There you can find ways to search broken down by main characteristics and described. 在这里,您可以找到按主要特征细分和描述的搜索方式。

现在,我使用helm-swoop ,它非常适合我的工作流程。

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

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