如何浏览当前在vim中打开的文件中的所有文件#included?

时间:2015-03-02 23:00:38

标签: c++ vim

假设我在.hpp中打开了以下vim文件:

#pragma once
#include "a.hpp"
#include "b.hpp"
#include "c.hpp"

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

现在,让我们说我想在任何包含的文件中搜索任何出现的术语Token(也可能在他们包含的文件中)。我怎么能这么容易地做到这一点?

我想跳过目前vimpath无法找到的任何文件,例如:在这种情况下,我的路径中可能没有boost所以我希望它不会在boost/something.hpp中搜索。

2 个答案:

答案 0 :(得分: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“的演讲Seven habits of effective editing

最后一个命令也在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}

答案 1 :(得分:0)

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

相关问题