Last Updated: February 25, 2016
·
3.867K
· sturmer

Rebuild Cscope database

Code navigation in Vim is great with Cscope. Cscope uses a file database (usually named cscope.out) with a list of symbols extracted from your code, but it needs to update it in order to reflect changes in the code.

In order to rebuild a Cscope database for use within Vim, have a script like the following in your project directory:

#!/bin/bash
# Usage: just source it

# You can specify a different directory, default is `pwd`.
# Only be sure to specify an absolute path.
codeDir=${1:-$PWD} 

# Go to the root directory, to create the database with absolute names
cd /

# Add lines like "-o -name '*.your_extension'" if needed
find $codeDir -name '*.cc' \
    -o -name '*.h' \
    -o -name '*.c' > $codeDir/cscope.files

# Build cross-references in the project's directories
cd $codeDir && cscope -b -q
export CSCOPE_DB=$codeDir/cscope.out

# Also use ctags
ctags -R .

In Vim, just do:

:cs add /absolute/path/to/cscope.out

Once in a while, source the script in the shell, and then within Vim:

:cs reset

Of course, you can have a cron job update it for you. Still, I have to figure out how to automate the cs reset within Vim :/

Credit: this is just an elaboration on Vim/Cscope tutorial