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
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 patternThis works, but it is awkward having to type (or copy/paste) the name to be searched for.
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
:set cst :set nocstThis is a variable (long form cscopetag) with the same short name as the command above (just to confuse you).
:set csto=0 :set csto=1This specifies the order for the :cstag command.
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.
:cs add cscope.out :cs showThe "show" command will tell you if vim has found your database.
I modified (mostly trimmed down) the recommended plugin file I ended up with the following in .vim/plugin/cscope_maps.vim
if has("cscope") set cscopetag set csto=1 set ttimeoutlen=600 nmapI 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).:cs find c =expand(" ") if $CSCOPE_DB != "" cs add $CSCOPE_DB endif endif
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.
If I want all the csource stuff, I'll run csource outside of vim.
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.
This code looks like this: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()
Tom's Computer Info / tom@mmto.org