2

I usually use cscope to browse my code. Whenever I hit C ] the current buffer I am reading changes and the file containing the definition is shown.

Suppose I have already a tab in vim with that file already open: is there anyway to jump from my current location directly to that file that is already open?

I don't need to split but just jump to a file already open in a buffer.

Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173

2 Answers2

2

You could come close to what you want with a combination of options:

" use the quickfix list/window for all cscope queries
set cscopequickfix=s-,g-,c-,d-,i-,t-,e-

" quickfix commands jump to the target buffer where it is displayed
set switchbuf=useopen,usetab

and a remapping:

" override the default <C-]> behaviour
nnoremap <C-]> :cs f g <C-R><C-w><CR>
romainl
  • 186,200
  • 21
  • 280
  • 313
  • What are the advantages of this mapping over `set cscopetag'? – Peter Rincker Apr 24 '14 at 15:37
  • @PeterRincker, `cscopetag` was my first idea but it doesn't have the expected behavior here. If it's only me, then `set cscopetag` is *obviously* a cleaner approach. – romainl Apr 24 '14 at 15:51
  • I am not going to lie, `'cscopetag'` has really let me down here. I just tried it and it doesn't obey `'switchbuf'` option (7.4 patches 1-52). Is this a bug? or feature? – Peter Rincker Apr 24 '14 at 16:12
  • @PeterRincker, 7.4.131 here. I'm fairly confident I experienced the same misbehavior in earlier 7.3 releases both on Linux and on Mac OS X: `:cstag` works as expected but `` doesn't. Hence the seemingly superfluous mapping. – romainl Apr 24 '14 at 16:54
1

For normal tags, there's the <C-W>] mapping and :stag command that splits the window before the tag jump.

For cscope, there's :cstag, but no :scstag, so you'd have to do separate commands, e.g.:

:split | cstag ...

You probably can modify / add the C ] mapping that you have in this way.

Ideally, this would consider the 'switchbuf' setting, and re-use an existing window showing that target buffer instead of doing a split. Unfortunately, Vim current doesn't behave this way, and implementing this yourself is difficult, mostly because you somehow have to get the target file before the jump to check the buffer availability via bufwinnr().

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324