This page is dedicated to the installation, configuration and integration of the free-software tool
for browsing source code symbols and definitions known as Cscope on Debian.
Cscope Manual Page
What is Cscope ?
"Cscope is a developer's tool for browsing source code. It has an impeccable Unix pedigree, having been
originally developed at Bell Labs back in the days of the PDP-11. Cscope was part of the official AT&T
Unix distribution for many years, and has been used to manage projects involving 20 million lines of code!"
- -From the official website
Cscope allows searching code for a variety of occurrences, including:
- all references to a symbol
- global definitions
- files including other files
- regex or text string occurrences
- functions calling a function, etc
The fuzzy parser was mainly designed for browsing C code, but is flexible enough to be used with C++/Java and general large text files (grep database).
The tool also features a command line mode, suitable for scripting/GUI backend work.
Cscope runs (and is frequently available in the native repositories) on a variety of *Nix operating systems, including GNU/Linux and BSDs.
Cscope also features Windows/MacOS support, though integration with other Unix based tools is tricky.
On Debian, a simple sudo apt-get install cscope should do.
Sources are available over at Sourceforce.
Note: (NOT in Debian's case) If your version of Vim wasn't compiled with '--enable-cscope', you will need to reconfigure and recompile Vim with that flag.
You can check if your version of Vim is compiled with the cscope flag by issuing the following command: vim --version | grep "cscope".
If the output contains "+cscope" then your version of Vim has cscope support.
1.Download the cscope_maps.vim file, and arrange for it to be read by Vim at startup time.
Stick the file in your $HOME/.vim/plugin directory (or in any other 'plugin' subdirectory in your 'runtimepath').
2.Go into a directory with some C code in it, and enter cscope -R (the '-R' makes Cscope parse all subdirectories, not just the current directory).
This will build the Cscope database and drop you into Cscope's default text user interface.
Move with the arrow keys and hit any of the numbers displayed on the left side to jump into Vim at the specified symbol location.
This method implies closing Vim every time you want to perform another Cscope search, which is not preferred.
Therefore, the next step will introduce the Vim plugin.
3.Open a source code file in Vim and hover the cursor over a frequently used symbol (eg. int in C).
Type "CTRL-\ s" (Control-backslash, then just 's') in quick succession, and you should see a menu at the bottom of your Vim window showing you
all the uses of the symbol in the program.
Select one of them and hit enter, and you'll jump to that use. As with ctags, you can hit "CTRL-t" to jump back to your original location before the search
(and you can nest searches and CTRL-t will unwind them one at a time).
A full tutorial on Cscope+Vim is available at http://cscope.sourceforge.net/cscope_vim_tutorial.html.
Footnote: In my personal use, the latest versions of Vim+Cscope don't accept the default
Control-backslash modifier combination, resulting in a broken experience.
I personally swapped the CTRL-\ modifier combination in the cscope_maps.vim file to an unused key such as 'z'.
Thus the full key combination becomes just z+s, z+f , etc.