Is there an alternative to ctags that works better?
I've spent quite some time struggling with this myself.
The closest I ever got was something called gccsense. Unfortunately, the project seems abandoned and moreover it was difficult setting it up because English was not the author's first language.
I ended up approaching the problem from another angle. I made the decision that intellisense/autocomplete was more important to my coding than having all the available features of vim, so I chose an IDE like Eclipse, and then found a plugin for Eclipse that emulates Vim. So far the best kind of plugin like that that I found was Viable.
Here is the full list of options that I have tried and found unsatisfactory:
- clang - requires you switch from gcc to a different and "better" compiler. The problem is gcc is much more mature [edit apparently you don't need to switch compilers see comments below, I may give this another try in the future.]
- gccsense - great idea (using gcc to give you the code completion) however work on the project is abandoned :( and the version that is up is beta quality
- xref in vim - xref is a great standalone tool and works great for parsing C. It can be made to work in vim with vxref, however from my experience xref lacks in parsing current C++ code and development on it has stopped (as well as development on vxref.)
- eclim - seems to work great for Java support using eclipse, extremely slow and completely unreliable when parsing C++ or C code. What usually happens is everything works for a long while, but then suddenly, the parser stops parsing any new code that you write, and nothing short of loading up eclipse itself and forcing eclipse to reparse the project seems to help. Also, less of an important fact, but more of an annoyance is that eclim takes over handling errors, so it screws up the way vim usually parses errors from gcc meaning you have no access to the quickfix list which is annoying.
- netbeans + jvi - alot of people swear by this, but I had all sorts of problems with jvi. One major problem I had was jvi would say I'm in normal mode, but really was in insert mode, nothing short of a restart would help.
- eclipse + viplugin/vrapper - this was beginning to look like the best option; each had its own set of bugs + lacking features, but still was most attractive, until I found viable which seemed to be the most stable and have the most features.
If you do find a solution you are happy with please share it in a comment, because I would be interested in it.
CScout version 2.8 offers a command-line option (-C) that will create a vim-compatible tags file for the C source code it will process. CScout is a source code analyzer and refactoring browser for collections of C programs. It can process workspaces of multiple projects mapping the complexity introduced by the C preprocessor back into the original C source code files. Consequently, the generated tags file contains correct information for entities, like functions, variables, and structures, that are created through preprocessor macros. CScout will process include files, using the include file paths specified in the code's project configuration file (the equivalent of a Makefile). To try it out, download the package matching your setup, go into the example directory containing the awk source code and run
../bin/cscout -Cc awk.cs
You can see some types of preprocessor constructs that CScout can handle in this page. For example, if you process the following code
#define typefun(name, type, op) \
type type ## _ ## name(type a, type b) { return a op b; }
typefun(add, int, +)
typefun(sub, int, -)
typefun(mul, int, *)
typefun(div, int, /)
typefun(add, double, +)
typefun(sub, double, -)
typefun(mul, double, *)
typefun(div, double, /)
main()
{
printf("%d\n", int_add(5, 4));
printf("%g\n", double_mul(3.14, 2.0));
}
CScout will generate a tags file with the following entries.
double_add test.c 8 ;" f
double_div test.c 11 ;" f
double_mul test.c 10 ;" f
double_sub test.c 9 ;" f
int_add test.c 4 ;" f
int_div test.c 7 ;" f
int_mul test.c 6 ;" f
int_sub test.c 5 ;" f
main test.c 13 ;" f
typefun test.c 1 ;" d
You can try it out yourself by adding a few code-generating macros in the example source code to see the tags CScout will create.
I haven't tried this myself yet, but clang_indexer
seems very close to what you are looking for (sources). It still uses an external database (i.e. doesn't index on the fly per se), but it seems to offer functionality one usually only finds in cscope
(which doesn't support C++ too well).
For autocomplete I use clang_complete. It doesn't require generating an index and works most of the time pretty well. It also can do automatic syntax checking in vim so one is warned of possible issues. It doesn't autocomplete the macro example you gave
#define blah(x) blah__ ## x
void blah_<TAB>
as bla__x
though (only as blah(x)
). It would be nice for this to be more configurable, but I wouldn't consider this broken either.