I am running vim 9.1 on Fedora 41. Typing "vim --version gives plenty of information, including "+cscope".
Time to start reading.
The built in stuff is all accessed via :cscope or just :cs
:cs find
The :cstag command searches both the ctags database and
the csource database.
The order is determined by the setting of "csto"
It works like this:
:cst
You use the "add" command to tell vim about a cscope database.
So far I find that I never need to do this, vim just finds one
either in the current directory or a parent directory.
I modified (mostly trimmed down) the recommended plugin file
I ended up with the following in .vim/plugin/cscope_maps.vim
I decided I didn't want Ctrl-\ to allow access to all the csource options,
but just the "c" option (to find all the places that call the thing
under the cursor). So my nmap does only that, and I get it with one
keystroke, just like Ctrl-] to find definitions.
I often launch vim within a project somewhere, and it won't find the
cscope.out database up in some parent directory. I found a fellow who
published his fix for that and put it into my .vimrc.
Here is a partial list of types.
s - find this C symbol
g - find this definition
d - find functions called by this function
c - find functions calling this function
t - find this text string
e - find this egrep pattern
This works, but it is awkward having to type (or copy/paste)
the name to be searched for.
Variables
Some of these must be set in the .vimrc file and will have no
effect is set within vim once it is running.
:set cst
:set nocst
This is a variable (long form cscopetag) with the same short name
as the command above (just to confuse you).
:set csto=0
:set csto=1
This specifies the order for the :cstag command.
When set to zero, the cscope database(s) get looked at first.
When set to one, the ctags database(s) get looked at first.
:cs add cscope.out
:cs show
The "show" command will tell you if vim has found your database.
My final setup
I am pretty happy with the following setup:
if has("cscope")
set cscopetag
set csto=1
set ttimeoutlen=600
nmap
I set csto to one so it uses ctags first to find things under the cursor
when I press Ctrl-] (like it always did when I just used ctags).
If I want all the csource stuff, I'll run csource outside of vim.
function! LoadCscope()
let db = findfile("cscope.out", ".;")
if (!empty(db))
let path = strpart(db, 0, match(db, "/cscope.out$"))
set nocscopeverbose " suppress 'duplicate connection' error
exe "cs add " . db . " " . path
set cscopeverbose
" else add the database pointed to by environment variable
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
endfunction
au BufEnter /* call LoadCscope()
Feedback? Questions?
Drop me a line!