# vim + ctags + gtags(+cscope)
### ctags:
```
$ sudo apt-get install exuberant-ctags
$ cd project/
$ ctags -R *
```
It will produce file "tags"
### gtags:
```
$ sudo apt-get install global
$ cd project/
$ find . -name "*.[ch]" > gtags.files
$ gtags
```
It will produce file "gtags.files, GPATH, GRTAGS, GSYMS, GTAGS"
### vim plugin
modify ~/.vimrc
```
set cscopeprg=gtags-cscope
cs add GTAGS
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
```
Then you can use ctag and gtags on vim
but remember, you need open file on project root
ex.
```
$ vim /project/folderA/fileA.c
```
Command:
* ctag:
```
C-] // Go to Definition
C-t // Go back
```
* gtags
```
C-\ and press s // find string on the project
```
If you update the code, you need update the tag
You can use following script:
### rebuild tag script (```buildtag.sh```)
```
#!/bin/bash
# sudo apt-get install exuberant-ctags
# sudo apt-get install global
file=gtags.files
echo Work directory is $PWD
cd $PWD
ctags -R *
if [ -f "$file" ]
then
global -u
else
find . -name "*.[ch]" > gtags.files
gtags
fi
echo Build tag Done
```
and use this command to rebuild:
If you put buildtag.sh on home directory
```
$ cd project
$ ~/buildtag.sh
```
Reference:
http://linux.byexamples.com/archives/385/vim-with-ctags-for-multi-level-directory-hierarchy/
http://ldshyu.blogspot.tw/2013/06/coding-tag.html
http://forum.ubuntu.org.cn/viewtopic.php?t=343460
http://cscope.sourceforge.net/cscope_maps.vim