Now I am learning how to use GNU GLOBAL in vim. I have installed gtags.vim. I have gtags the kernel source directory. The .vimrc includes the following lines:

set cscopetag
set csprg=gtags-cscope                                             
cs add GTAGS

Assume that I am editing the file arch/x86/kvm/x86.c and the cursor is on the function call kvm_lapic_enabled(). Now I press ^], the vim complains like this:

E429: File "arch/x86/kvm/lapic.h" does not exist
E257: cstag: tag not found

If I remove the set cscopetag in .vimrc, the vim will complains like this:

E433: No tags file
E426: tag not found: kvm_lapic_enabled

So I guess that in the first case, vim used the tag file generated by gtags to locate the function and learned that it is defined in arch/x86/kvm/lapic.h. However, vim seems to lookup this file under current directory, that is arch/x86/kvm/arch/x86/kvm/lapic.h, when using cscope by default. So how to configure vim to let ^] can utilize the GTAGS correctly? Exactly, how to configure the cscope find command to use the GTAGS correctly?
Thanks very much!

  • 1
    Here are the things I've done to get gtags-cscope to work properly within Vim. Execute cs add GTAGS <project-directory> -a where <project-directory> is the name of the directory in which gtags was run and in which GTAGS resides. The -a flag tells gtags-cscope to output absolute file names. Also let $GTAGSDBPATH = <project-directory> and let $GTAGSROOT = <project-directory>. – garyjohn Oct 6 '15 at 15:49
  • @garyjohn I add cs add GTAGS $PWD to solve this problem now. However, you have to open vim under the root directory of the project. – tamlok Oct 7 '15 at 7:45
  • 1
    Or you could have Vim figure out what the root directory of the current project is and set the third argument to cs add accordingly. How you do that depends on how and where you start Vim and on how your projects are structured. I have a script that uses the directory in which Vim starts to figure out the current project directory. If no project directory is found, as when starting Vim in $HOME, then the script uses the full path of the first file opened in a project to determine the project directory. There are also some scripts at vim.sourceforge.net for doing this. – garyjohn Oct 7 '15 at 14:29
  • @garyjohn Yes, scripts like that will be helpful and convenient. Thanks very much! – tamlok Oct 8 '15 at 0:36
  • @garyjohn your vi.stackexchange.com/questions/4991/… worked great for me --- thanks! – cxw May 5 at 14:32

Your Answer

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

Browse other questions tagged or ask your own question.