Gnu Global, the programmer’s friend
May 25th, 2010 mysurface
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
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.
"gtags
: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.
Posted in Developer, global, gtags, gvim, vi, vim | Hits: 46757 | 3 Comments »
Live Chat!







