I wanted to test if I can handle working on C++ projects in vim (well actually neovim). These were the core features, that I wanted to have:

  • syntax highlighting
  • window splitting
  • go to definition
  • autocompletion

The first two ones are obvious, so I got to setting up the third. I already knew about ctags, but I wanted to check if it works for me. I created two files:


#include "test.hpp"

void foo(int* a)

int main()
    int a = 5;


void bar(int i)


void bar(double d)


By running ctags ./*, I created the corresponding tags file:

!_TAG_FILE_FORMAT   2   /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED   1   /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_MODE   u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME  Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL   https://ctags.io/   /official site/
!_TAG_PROGRAM_VERSION   0.0.0   /45968eff/
bar ./test.hpp  /^void bar(double d)$/;"    f   typeref:typename:void
bar ./test.hpp  /^void bar(int i)$/;"   f   typeref:typename:void
foo ./test.cpp  /^void foo(int* a)$/;"  f   typeref:typename:void
main    ./test.cpp  /^int main()$/;"    f   typeref:typename:int

So being in main and pressing Ctrl-] on foo(&a) jumps straight to the right function. The problem is, that when I am on bar(a) and I do that, the windows switches to test.hpp, but the double d overload of the function is selected (I know it could through implicit conversion, but I have a better overload), not the one taking an int as an argument.

So my question here is: can I somehow configure vim or ctags to make it so I jump to a proper definition when using vim?

  • BTW I could not find quickly whether one of the newer language server for c++ (clangd, ccls/cquery) support finding the correct overloaded function definition. Afaik, ctags will never support this. It only considers the identifier under the cursor and no context. The new parser in universal-ctags does not change this.
    – Hotschke
    Mar 10 '19 at 10:32
  • I have tried clangd and for me it actually did the trick. You find my test as an answer in the referenced question: vi.stackexchange.com/a/19153/1292
    – Hotschke
    Mar 10 '19 at 16:36