As far as I understand Vim has a built-in support for tags (ctags in this case)

Now I have a common C source and C header file. The header file has void foo(void); and the source file has void foo(void) { /* */ }.

Now when I'm in the source file, I can use :tags foo, it will jump to the function definition in the source file. But if I use :tnext now, it won't jump to the function declaration in the header file.

I feel like this should be somehow possible. Is it?

  • 1
    (how) did you run ctags? Also, see :h gD.
    – VanLaser
    Jun 12, 2016 at 15:24
  • I just ran ctags -R, that was the mistake
    – hgiesel
    Jun 12, 2016 at 17:24

1 Answer 1


Okay I've done it:

It all has to do with ctags: First create two files called foo.c and foo.h to test it: In foo.h write down:

int bar(void);

In foo.c write down:

int bar(void) { /* */ }

And in the directory where those two files is, execute:

ctags --list-kinds

You get a long list of languages with there types of tags. Find C. Notice the following line:

p function prototypes [off]

I would call it function declaration but anyway. So you need to activate tags for function prototypes when executing ctags. You do that by calling:

ctags -R --c-kinds=+p

Notice that the same applies to any other languages, e.g.:

ctags -R --java-kinds=+l

Now you can open foo.c (vim foo.c) and enter :tag bar. It will show you the function definition. Enter :tnext and you will jump into foo.h to the declaration of bar.

However also notice that ctags doesn't care about correctness. E.g. the bar declaraction couldn't even apply to the definition of bar, as I havn't included the header file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.