简体   繁体   English

如何跳转到C / C ++函数声明而不是它的定义?

[英]How to jump to a C/C++ function declaration instead of its definition?

I know CTRL+] to jump to definition of a function in various languages in vim. 我知道CTRL +]跳转到vim中各种语言的函数定义。 What about jump to declaration in C/C++ header? 如何跳转到C / C ++头文件中的声明?

Since I have plenty of headers containing meaningful comments/explanations, I would frequently find function declarations among a large code base. 由于我有大量包含有意义的注释/解释的标题,我经常会在大型代码库中找到函数声明。 Is there some sorts of shortcuts to do this? 有没有一些快捷方式可以做到这一点?

ctags does not add function prototypes by default. ctags默认情况下不添加函数原型。 You have to add the option 您必须添加该选项

--c++-kinds=+p --c ++ - 种= + P

to support function prototypes. 支持功能原型。 My ctags looks like this: 我的ctags看起来像这样:

ctags --c++-kinds=+p --fields=+iaS --extra=+q *.h *.c ctags --c ++ - types = + p --fields = + iaS --extra = + q * .h * .c

When you are at a tag, you can use the following editor commands to browser through the tags (Meaning the same tag occuring multiple times as definition/declaration)- 当您处于标记时,可以使用以下编辑器命令浏览标记(意味着相同的标记出现多次定义/声明) -

tn (Next Tag) tn(下一个标签)

tp (Previous Tag) tp(上一个标签)

I am satisfied with cscope, which includes header files in database. 我对cscope很满意,它包含数据库中的头文件。

Just put cscope_maps.vim in ~/.vim/plugin/ and then CTRL-] will list all choices if a cscope database is built. 只需将cscope_maps.vim放在〜/ .vim / plugin /中,然后CTRL-]将列出构建cscope数据库的所有选项。

To build a cscope database, just type 要构建cscope数据库,只需键入即可

cscope -bR

Based on Bram's 7 habits , without any plugin, you can do 根据Bram的7个习惯 ,没有任何插件,你可以做到

1) Set the path to your headers(This is crucial to work with point 2 below) 1)设置标题的路径(这对于使用下面的第2点至关重要)

:set path+=/path/to/headers

2) Then do one of the following command 2)然后执行以下命令之一

[I Display all list where keyword under cursor is in header files or [I显示光标下的关键字在头文件中的所有列表

[<Tab> will jump there and you can come back to your file using Ctrl + 6 [<Tab>会跳到那里,您可以使用Ctrl + 6返回到您的文件

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

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