update cscope db from vim
I use cscope with vim. When doing large edits for several files,开发者_如何学JAVA 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
First, you need to update cscope database.
:!cscope -Rbq
Then, reinit the database from vim.
:cs reset
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.
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.
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.)
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>
精彩评论