Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top