Reputation: 2070
I use vim with gtags plug in to read code through multiple files. Everything is okay except that I donnot know how to navigate back to the previous position before I run :CtagsCursor to jump to the token definition. I read through the GNU global online docs, but find nothing useful. But in the chapter "3.4 Elvis using GLOBAL", it says "CTRL-T return to the most recent tag context.", which is exactly what I wants. No idea why the function is not implemented for vim, or something is wrong with me?
BR, Ruochen
Upvotes: 4
Views: 3463
Reputation: 13
GNU GLOBAL has two handy vim plugins gtags.vim
and gtags-cscope.vim
.
The heading comment of gtags-cscope.vim
says that it is used to integrate GLOBAL with Vim's cscope
interface.
So what you have to do is:
cp /path/to/global-source/*.vim ~/plugin/
~/.vimrc
The heading comment of gtags-cscope.vim
has all the available options.
In my case, I use the following:
" To use the default key/mouse mapping:
let GtagsCscope_Auto_Map = 1
" If you hope auto loading:
let GtagsCscope_Auto_Load = 1
" Don't show warning if GTAGS not found
let GtagsCscope_Quiet = 1
" To use 'vim -t ', ':tag' and '<C-]>'
set cscopetag
Upvotes: 1
Reputation: 365
I solved the problem by using gtags-cscope
as cscopeprog
. Additionally I activated cscopetag to use cscope for ctag lookup in vim, too. This way, if you press <C-]>
you search for the declaration in gtags and <C-t>
to go back again.
For lookups of references, which I mapped to <C-\>
, I use the quickfix window. This does not use the tag stack and <C-t>
will not work.
I tried it, using the tag stack, but this leads to a cluttered tag stack and a large selection window. If you lookup multiple references you have to press <C-t>
multiple time, that's why I decided using the quickfix approach instead.
Here is my actual config.
set cscopeprg=gtags-cscope
if has('cscope')
set cscopetag cscopeverbose
if has('quickfix')
set cscopequickfix=s-,c-,d-,i-,t-,e-
endif
map <C-\> :cs find c <C-R>=expand("<cword>")<CR><CR>
endif
If you like to give the reference lookup without quickfix a try, remove the c-
option in cscopequickfix
.
Another hint, cscopeverbose
is a option to print error messages when using cscope. Otherwise you won't get errors (e.g. no gtags file added, or symbol not found).
EDIT 1:
To load a GTAGS file, use the built-in command cs add ./GTAGS
.
Upvotes: 1
Reputation: 303
I've looked through the docs and it seems tag stack isn't supported with gnu-global in vim according to section 3.5.1. Features: http://www.gnu.org/software/global/globaldoc_toc.html#Features_0028Vim_0029
In the above description, there is a link to setting up the plugin which uses tag stack, so check that out.
Other than that using ctrl-o
and ctrl-i
as substitutes should work fine.
Upvotes: 0
Reputation: 196596
<C-t>
is a built-in command related to Vim's "tag stack".
It looks like the plugin you are using doesn't implement a similar feature (and doesn't interact with the tag stack anyway) so you are left with <C-o>
/<C-i>
to jump around the jump list.
Upvotes: 3