Cscope

Cscope is a very powerful interface allowing you to easily navigate C-like code files. While Cscope comes with its own stand-alone interface, Vim provides the capability to navigate code without ever leaving the editor. Using Cscope, you can search for identifier or function definitions, their uses, or even any regular expression. With the proper configuration, "standard" include files of your compiler are automatically searched along with your sources. The output from :help :cscope says it all:

Here we set up a number of command-line-mode abbreviations to make cscope commands easier to type. These abbreviations can be made less intrusive by making sure they only trigger at the start of the command line, so that you can still type them normally in most cases where you don't actually want to use Cscope (for example, you may want to use css as a file extension sometimes). In Vim 7.0 or higher, this is easily done as follows:

We define a command :Cscope which will try to open the cscope database for the Vim source, and tell cscope that the relative paths in it are relative to the src directory containing the database itself (this assumes that the $VIMSRC variable has been set to the top directory of the Vim source.

Before you can use cscope on a set of source files, you must have a cscope database applying to them. You could set up commands in Vim to generate one (or more), or you can set up a script to do it outside of Vim. Another nice option would be to generate a new database from your makefile, to allow you to easily use all the same files that get compiled into your project. For instance, the following patch to the Vim src/Makefile adds a few targets related to generating a cscope database for the Vim source (and the "usual" include files, which cscope is clever enough to find):

If you rebuild the cscope database while Vim has a cscope connection open, the new database won't be used until either (a) you kill and re-add the database, or (b) you use :cs reset --Tonymec 04:40, November 25, 2009 (UTC)