update cscope db from vim
Asked Answered
J

5

23

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

Juliannejuliano answered 30/4, 2010 at 10:59 Comment(1)
Take a look at: vim.wikia.com/wiki/…Kemper
O
33

First, you need to update cscope database.

:!cscope -Rbq

Then, reinit the database from vim.

:cs reset
Olander answered 4/8, 2010 at 6:19 Comment(2)
When there is an existing connection to the cscope database cscope.out, cscope creates another one ncscope.out. How to replace the old database? I am using a Windows cscope port.Bursary
error: "cscope: -q option mismatch between command line and old symbol database"Kisner
K
9

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.

Karakul answered 24/9, 2013 at 14:6 Comment(0)
R
4

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.

Reincarnate answered 7/7, 2015 at 21:23 Comment(0)
A
2

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

Assentor answered 31/8, 2011 at 17:36 Comment(1)
Oops. I forgot that since I use enormous cscope databases that take seconds to search, I rarely call vim's cscope commands directly. I've updated the answer to reset the cscope connection.Assentor
G
2

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>
Garate answered 22/5, 2018 at 22:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.