I know CTRL+] to jump to definition of a function in various languages in vim. What about jump to declaration in C/C++ header?
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?
A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
You can't call a function without declaring it first.
In C, if a function is called before its declaration, the compiler assumes the return type of the function as int.
Try it Yourself » A function consist of two parts: Declaration: the function's name, return type, and parameters (if any) Definition: the body of the function (code to be executed)
ctags does not add function prototypes by default. You have to add the option
--c++-kinds=+p
to support function prototypes. My ctags looks like this:
ctags --c++-kinds=+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)
tp (Previous Tag)
Based on Bram's 7 habits, without any plugin, you can do
1) Set the path to your headers(This is crucial to work with point 2 below)
:set path+=/path/to/headers
2) Then do one of the following command
[I
Display all list where keyword under cursor is in header files or
[<Tab>
will jump there and you can come back to your file using Ctrl+6
I am satisfied with cscope, which includes header files in database.
Just put cscope_maps.vim in ~/.vim/plugin/ and then CTRL-] will list all choices if a cscope database is built.
To build a cscope database, just type
cscope -bR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With