(Apologies for the C tag, I did it for the syntax highlighting. This is more of a vim question. If someone more learned than I thinks the tag should be removed please do so)
Say I've got this directory structure:
Directory ~/Code/Test/ containing file1.c file2.c file4.c and Sub
Directory ~/Code/Test/Sub/ containing file3.c
file1.c:
#include <stdio.h>
#include "file2.c"
#include "Sub/file3.c"
void function1();
int main (int argc, char *argv[]) {
function1();
function2();
function3();
return 0;
}
void function1() {
printf("1\n");
}
file2.c:
#include <stdio.h>
void function2();
void function2() {
printf("2\n");
}
Sub/file3.c:
#include "../file4.c"
void function3();
void function3() {
printf("3\n");
function4();
}
file4.c:
#include <stdio.h>
void function4();
void function4() {
printf("4\n");
}
In any one of those files it should be possible to jump to the definition of the functions it uses from the other files. So for example, file1 should be able to jump across to file2, file1 should be able to jump down a directory to file3, file3 should be able to jump up a directory to file4, and here's the kicker; all of the files should be able to jump to the definition of printf. I also shouldn't have to copy the tags for the c library implementation into the Test directory in order to do this.
I'm wondering how I could go about doing this. I'm really not keen on monolithic tags files. Having a vim-wide tags file horrifies me. A tags file per directory annoys me. A tags file per project is bearable. But what I'd really like is a tags file per source file, and then a way to specify which tags files vim should be referring to.
Ideally I'd like to be able to just ctrl-] on anything and have vim jump to the correct definition based on what's in scope, just like visual studio. I'm beginning to suspect this can't be done, and if it is (via some combination of plugins) it would be extremely slow, which is really annoying because I was totally on the "Vim can do anything your newfangled IDEs can do" bandwagon for a couple of weeks there. Yes it's definitely the most powerful text editor I've come across, but as an IDE it's extremely unpolished. When I use the "Go to definition" command I expect to be taken to the correct definition whether it's a local variable, in a different file, in a standard library etc. Vim so far has given me hilarious results such as jumping across from a java file to a c file. And you have to use a separate command to jump to the definition of a local variable... What? (If there's a reason behind this I'd be interested in knowing)
I'm aware of wacking set tags=./tags
in my .vimrc and that's what I've done so far. But this won't scale if I work on something massive that links separate assemblies and source files from separate projects together.
(To be fair to vim, visual studio doesn't let you jump across assemblies to find definitions either, but it does at least have the good grace to serve up a header file from which you can "load assembly" and navigate to the actual source code you're looking for)