3

I know the way to go to the function declaration (using ctags + Ctrl + ]). But what if I want not to go to the function declaration, but to the function definition instead.

For example:

// foo.c
#include "foo.h"

...
if (x > 3) foo_function(x);
...

void foo_function(int x) {
    ...
}

and

// foo.h
void foo_function(int x);

Then Ctrl + ] opens foo.h and points to the void foo_function(int x); line. I want to go to the foo.c to the foo_function definition. I have taglist installed, but don't want to open the taglist window every time I just want to jump to the function definition under cursor. Is there a way to do this with a keymap?

Thanks.

Victor Zamanian
  • 3,100
  • 24
  • 31
maverik
  • 5,508
  • 3
  • 35
  • 55

3 Answers3

3

Use g] to get a picklist first

sehe
  • 374,641
  • 47
  • 450
  • 633
1

If you add the mappings suggested in :help cscope-suggestions, then you can use ^- g (control minus, then g -- nicely enough, even though the mappings were defined with <C-_>, vim lets you skip the shift key) to find the definition of the function under the cursor.

You could of course use any key mappings; I've seen control+\ as the default mapping in a cscope plugin.

sarnold
  • 102,305
  • 22
  • 181
  • 238
1

As similar question was already asked on stack overflow:

Get ctags in vim to go to definition, not declaration

You may find answers there helpful.

Community
  • 1
  • 1
mMontu
  • 8,983
  • 4
  • 38
  • 53