Has anyone used GNU global with vim? I'm navigating through a large C++ code base and have some trouble figuring out how to use it. I want to use its gtags-cscope functionality but I can't figure out how to generate a cross reference database which later I can connect to vim.

Any help in finding the solution is appreciated.

  • 1
    GNU Global didn't support JavaScript back when I tried it but it worked well with PHP and IIRC the Vim integration was pretty straightforward. Could you detail what you tried and how it failed? – romainl Sep 24 '15 at 7:41
  • @romainl I'm used to regular cscope. What was confusing to me is what file to use for a cross reference for a database. There are multiple files, but I seem to get the same result not matter what I use for a database. The tool doesn't always produce the right result. Have you had any issues with it? This is the codebase I'm trying to navigate – flashburn Sep 24 '15 at 16:21
  • I use GNU global cscope for my PHP projects. I use the instructions found here. Summarized: :set csprg=gtags-cscope, :cs add GTAGS. Have you at least done these commands? – Peter Rincker Sep 24 '15 at 16:55
  • @PeterRincker Yes I have. I doesn't always find the right "thing" for me. – flashburn Sep 24 '15 at 17:25

GNU Global's distribution already has a couple of vim scripts that are pretty handy.

Look for 'gtags.vim' and 'gtags-cscope.vim' (the most adequate probably for what you want) in Global's installation directory, and just copy the one you prefer to your 'plugins' dir inside vim's config. The second script will do a

    set csprg=gtags-cscope

for you, which will route all normal cscope commands through the gtags provider and so will use GNU Global's DB when searching.

I prefer to simply use the :Gtags command directly though, which I find easier to use, but to each his/her own..

The plugin gen_tags can also help for easily rebuilding your source code DB directly from vim.

| improve this answer | |

In the source code directory use the following command:

find . -name '*.cpp' -o -name '*.h' > gtags.files
gtags --accept-dotfiles -c -f gtags.files

This will build the cross reference.

In vim, you can issue the following command to invoke gtags-cscope

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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