Question

I use cscope with vim. When doing large edits for several files, cscope will report old line numbers for changed files. How can I rebuild cscope db from vim without losing

  • opened tabs/windowses in vim
  • connection with cscope engine

Thanks

Was it helpful?

Solution

First, you need to update cscope database.

:!cscope -Rbq

Then, reinit the database from vim.

:cs reset

OTHER TIPS

Building on a previous answer, add this to your .vimrc:

map <F5> :!cscope -Rb<CR>:cs reset<CR><CR>                                      

Then use F5 within vim to do the refresh.

-b = Build cross-reference only. -R = Recurse subdirectories during search for source files.

I use a script that keeps building my indexes in the background:

" We need to setup the function that reset cscope.
"You could define this in your vimrc instead.
vim --servername GVIM --remote-send ":function! ResetCscope()<CR>cscope reset<CR>endfunction<CR>"

while true ; do
    echo building...

    ctags -R
    cscope -Rbk
    vim --servername VIM --remote-expr "ResetCscope()"

    echo done. sleeping.
    sleep 1m
done

(It's actually a lot more complicated than that.)

The vim call should reload the cscope database in vim if you started it with vim --servername VIM. (I use a background command to run cscope queries, so I'm not sure about this. The command launches cscope independently and doesn't use Vim's connection.)

cscope_dynamic

cscope_dynamic does all you ask, and even more:

  • autoloads the database when you open vim.
  • loads the local cscope database if it exists, instead of the global one.
  • gracefully handles the connection
  • automatically saves changes to database
  • it is much much faster, especially when working with large source base

How is it faster?

It uses two databases:

  • small database: it is updated frequently, with small changes, so it is really fast
  • big database: it is updated less frequently by merging the small database into this one.

Edit: Feb17: Removed old answer as cscope_dynamic does all these out of the box.

Tried this recently in gVim 8.0 on Windows, but even after the cs reset, vim was locking cscope.out so cs could not regenerate cscope.out with vim open.

In this case, I added the following additional mapping (F12 in e.g) which kills the current cscope connection so cscope can regenerate the cscope.out with F11, without having to close the vim. Hope this helps some one.

map <F11> :!cscope -Rbq<CR><ESC>:cs add cscope.out<CR><CR> 
map <F12> :cs kill cscope.out<CR><CR>

Based on previous answers, this is what you do when your current directory is not the same as the one your cscope.out file is located:

map <F5> :!cd /your/cscope.out/dir/ && cscope -bk<CR>:cs reset<CR><CR>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top