我该如何在vim中搜索当前打开文件所包含的所有文件?

4
假设我在vim中打开了以下的.hpp文件:
#pragma once
#include "a.hpp"
#include "b.hpp"
#include "c.hpp"

#include <boost/something.hpp>
// some code

现在,假设我想在任何包含文件中搜索术语“Token”的任何出现(可能在它们所包含的文件中)。 我如何轻松地做到这一点?
我希望跳过当前“vimpath”无法找到的任何文件,例如在这种情况下,我可能没有在我的路径中使用“boost”,因此我希望它不要在“boost / something.hpp”中搜索。

您是否也想在STD中搜索“Token”? - NaCl
1
只有当@NaCl在路径中时,例如如果我可以gf文件,那么它应该搜索它。 - quant
2个回答

1
你可以使用vim中可用的include-search功能。特别是,当光标停留在单词上时,这是搜索所有Token出现的命令:
[I          Display all lines that contain the keyword under the
            cursor.  Filenames and line numbers are displayed
            for the found lines.  The search starts at the
            beginning of the file.  {not in Vi}

要跳转到第一个出现的位置,您可以使用:

[<Tab>

这段内容摘自Bram在26分08秒时的演讲有效编辑的七个习惯

Vim帮助文档中也对该命令进行了描述:

[ CTRL-I    Jump to the first line that contains the keyword
            under the cursor.  The search starts at the beginning
            of the file.  Lines that look like a comment are
            ignored (see 'comments' option).  If a count is given,
            the count'th matching line is jumped to, and comment
            lines are not ignored.  {not in Vi}

0

查看 :help include-search 以了解在 Vim 中自动搜索包含文件的几种方法。对于简单的标记搜索,[i 可能是最简单的解决方案。如果您需要完整的正则表达式,或者如果您没有标记可以将光标放在上面,您可以使用 :isearch 命令。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接