Gnu Global, the programmer’s friend

May 25th, 2010 mysurface Posted in Developer, global, gtags, gvim, vi, vim | Hits: 326730 | 11 Comments »

GNU Global (gtags) is a source code tagging system similar to ctags but more than that. I always use vim as my c/c++ source code editor, and using ctags to helps me travels from function call to function definition. I do write a post indicates how does ctags works with vim.

The reason I shifted to gtags is because ctags is no longer sufficient to me. I have to trace the codes from large volume than last time, and they scatter into many different folders.

Gtags provides me not only travels to definition of the function calls, but also allows me to locate the function calls from the definition, the reverse way. To be precise, it capable of locate object definitions, object references, both of them based on patterns I specified.

Gtags works with vim too, by doing some keymaping tweaks, it works the same like ctags do, and more.

To get gnu global install to your system, check out the official website’s download page.

After the installation, goto your root path of your c/c++ project, and trigger this and go make a coffee.


Gtags will pickup whatever needed and create FOUR tagging db file, refers here for more info.

In order to allow Gtags working in vim, you have to copy over the gtags.vim into vim plugin’s folder. ( Refers to here on how to install vim’s plugin script.)

Vim with gtags
For vim with ctags, hitting Ctrl+] will jump you to object definition, I gonna do the same for vim with gtags. Besides that, I gonna map Ctrl+\ to list all the object references.

Now, lets us edit vimrc, copy and paste those lines into your vimrc.

:map <C-]> :Gtags<CR><CR>
:map <C-\> :Gtags -r<CR><CR>
:map <F10> :cclose<CR>
:map <F11> :cp<CR>
:map <F12> :cn<CR>

*nix, vimrc is at ~/.vimrc
windows gvim, Edit > Startup Settings

When Gtags list all the object references, it will open a split windows, to travels from one to another, use :cn and :cp, to close the split windows use :cclose, all are mapped to F11, F12 and F10.

You can find your codes in your shell too, by using command global.

To list all definitions of “GetExecute”, you do this:

global GetExecute

For more details listing, you can add in -x option, which it will print out the line as well as the line number.

global -x GetExecute

To list all the references of “GetExamples”, you do this:

global -rx GetExamples

You can add in your regex in your search such as *, see this:

global -rx GetLinuxBy*

You can search by symbol as well as grep too.

global -sx GetLinuxBy*
global -gx GetLinuxBy*

And more.

Thanks to Shigio YAMAGUCHI, Hideki IWAMOTO et al. for such wonderful tools and hope you enjoy coding with global.

11 Responses to “Gnu Global, the programmer’s friend”

  1. wow, this is what i’ve been looking for when coding in bash, thanks a lot man

  2. Yo mypapit! Nice to hear from you again!

  3. long time since your last update.

  4. Wade Berrier Says:

    The global documentation says that vim’s “tag stack” isn’t supported in gtags.vim.

    Anyone know how to make gtags work with a tag stack?

  5. I own and operate a pretty popular celeb chatter website, and to remain on top of things, I utilize marketplace pulse tools.Your URL has been burning up time-tested Alexa triggers, and I figured I’d check it out and check into if I could discoverwhat all of the buzz was about.

  6. I’ve installed global 6.2.11 and also gtags.vim. But I got this error while using Ctrl + ] :

    Gtags for pattern: module_InitBankError: global command failed. command line: global –result=ctags-mod -qre ‘module_InitBank’

    And if I just type the cmd in the shell:
    $global –result=ctags-mod -qre ‘module_InitBank’

    It shows nothing…

    Could you please help me out with this? I don’t know what’s wrong with it.

  7. Oh…I just delete the previously generated GTAGS related files and do gtags again. It all works fine now…Thanks anyway! :D

  8. Learn basic linux stuff at

  9. which is facet is irresistible to animatorsIssey Miyake headband upon Ultimo. luciano Dior Monsieur sportcoaround and thus Dior Sportif leg protection secure Pines for men forceful, school yard ridge. cotton turtleneck, $175; at just Ultimo. and don’t forget the more replica Prada tote bags usual however excellent metal plastic a combination picture frames. lots of people are acetate on Prada BR5071 the top combined with temples or wats precious metal on the bottom. most of these over and over a

  10. When you come for holiday you will need to service. Kaya Transfer can help you about Dalaman Airport Transfers. You will have cheap and safe Dalaman Transfers. Kaya Transferdoing Fethiye Transfers, Marmaris Transfers, Oludeniz Transfers, Icmeler Transfers, Kalkan Transfers, Dalyan Transfes and Sar?germe Transfers from Dalaman Airport. If book for Dalaman Transfers you can pay cash to driver when you arrivel. Also you will have soft drinks and free WIFI in your Dalaman Airport Transfers.

  11. Hi There, this is very helpful you have explained it very clear.

Leave a Reply