Gnu Global, the programmer’s friend
May 25th, 2010 mysurface Posted in Developer, global, gtags, gvim, vi, vim | Hits: 310039 | 9 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
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.
May 27th, 2010 at 1:12 pm
wow, this is what i’ve been looking for when coding in bash, thanks a lot man
May 27th, 2010 at 9:09 pm
Yo mypapit! Nice to hear from you again!
June 22nd, 2010 at 5:31 pm
long time since your last update.
December 9th, 2010 at 6:57 am
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?
May 19th, 2011 at 1:29 am
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.
March 13th, 2014 at 4:02 pm
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.
March 13th, 2014 at 4:09 pm
Oh…I just delete the previously generated GTAGS related files and do gtags again. It all works fine now…Thanks anyway! :D
January 7th, 2015 at 4:05 pm
Learn basic linux stuff at http://mylinuxtrick.blogspot.in
May 20th, 2015 at 2:56 pm
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