简体   繁体   English

无法在Emacs中有效搜索

[英]Unable to search effectively in Emacs

I want to have a similar tool in Emacs as the following in Vim 我希望在Emacs中有类似的工具,如Vim中的以下内容

 :g/search/

to get a list of matches. 获得匹配列表。

How can you get a list of matches in Emacs? 如何在Emacs中获得匹配列表?

Mx occur ? Mx occur吗?

From the manual : 手册

Mx occur

Prompt for a regexp, and display a list showing each line in the buffer that contains a match for it. 提示正则表达式,并显示一个列表,显示缓冲区中包含匹配项的每一行。 The text that matched is highlighted using the match face. 匹配的文本使用match面突出显示。 To limit the search to part of the buffer, narrow to that part (see Narrowing). 要将搜索限制为部分缓冲区,请缩小到该部分(请参阅缩小)。 A numeric argument n specifies that n lines of context are to be displayed before and after each matching line. 数字参数n指定在每个匹配行之前和之后显示n行上下文。 The default number of context lines is specified by the variable list-matching-lines-default-context-lines . 上下文行的默认数量由变量list-matching-lines-default-context-lines

In the *Occur* buffer, you can click on each entry, or move point there and type RET , to visit the corresponding position in the buffer that was searched. *Occur*缓冲区中,您可以单击每个条目,或在那里移动点并键入RET ,以访问已搜索的缓冲区中的相应位置。 o and Co display the match in another window; oCo在另一个窗口中显示匹配; Co does not select it. Co没有选择它。 Alternatively, you can use the Cx ` ( next-error ) command to visit the occurrences one by one (see Compilation Mode). 或者,您可以使用Cx `next-error )命令逐个访问事件(请参阅编译模式)。

Typing e in the *Occur* buffer switches to Occur Edit mode, in which edits made to the entries are also applied to the text in the originating buffer. *Occur*缓冲区中键入e切换到Occur Edit模式,其中对条目所做的编辑也应用于原始缓冲区中的文本。 Type Cc Cc to return to Occur mode. 键入Cc Cc以返回Occur模式。

The command Mx list-matching-lines is a synonym for Mx occur . 命令Mx list-matching-linesMx occur的同义词。

In addition to Mx occurr check also Mx grep. 除了Mx occurr还检查Mx grep。 This works in several files at once. 这可以同时在多个文件中使用。

My usual workflow is not to get a list and choose (don't know how to do that), but to use the incremental search: 我通常的工作流程不是获取列表并选择(不知道如何操作),而是使用增量搜索:

C-s <search target>

gets the fist match after the point. 在点之后获得第一场比赛。 If you don't like it another Cs gets the next one. 如果你不喜欢它,另一个Cs会得到下一个。 Continue until you're happy (you'll need an extra Cs to wrap around from the and of the buffer). 继续,直到你感到高兴(你需要一个额外的Cs来包围缓冲区)。 New enough emacsen can also highlight all the matches that are visible. 足够新的emacsen还可以突出显示所有可见的匹配。

As noted in the comments by Török Gábor, this is the typical keybinding of isearch-forward . 正如isearch-forward的评论中所指出的,这是isearch-forward的典型键绑定。 In the event that your bindings are different, you need to modify the prescribed procedure. 如果绑定不同,则需要修改指定的过程。

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

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