cscope, ctags, & vim

cscope, ctags, and Vim are powerful tools for reading a lot of code. ctags can be used to take you to the definition of a variable (e.g., a function, variable, or macro). cscope can be used to take you to the call site of a definition (e.g., all function calls, all variable uses, all macro uses). These tools can be used independently of Vim, but having a powerful editor that can use these tools in an integrated fashion speeds development.

Theory of cscope, ctags, & vim

Your choice of tool will depend on the language you are developing in primarily:

You instruct cscope and ctags to build a database for a directory tree. These databases are a list of <variable, line_number> pairs sorted by 'variable'. Vim does a binary search on these databases to answer your queries (e.g., find definition of 'variable' means searching the database to find the appropriate variable='variable', then moving the cursor to that line_number).

Vim allows you to specify the order in which it searches its databases. Typically your list of databases will be ordered as such:

Setting up cscope, ctags, & vim

We first have to build our databases. When you build the database you want to make sure your repository system ignores the database files as they are generated and will waste space in your versioning database (that you won't be able to reclaim). The running example used here will focus on the Linux kernel using git.

Conclusions

Good luck. The key to understanding technology is using it. Go ahead and try to incorporate these scripts into your work process and you should see a rapid improvement in development speed.

Last updated: Fri Nov 14 15:39:26 EST 2008