How to use cscope under vim

CScope is a tool allowing to easily explore your code. The following steps should be done in order to use it under vim:

  • install cscope if not already (under fedora sudo dnf install cscope)
  • go to the folder containing your code (*.cpp, *.hpp, or other)
  • create a database with the following command cscope -b. The result of this command is a file named cscope.out
    • if you want to use recursive search during the database creation cscope -Rb
    • or if you want to precise the types of files you want to index cscope -Rb -i cscope.files where cscope.files is previously created with
    • find . -name "*.cpp" -o -name "*.hpp" -o "*.h" >> cscope.files for instance (the first “-o” is for OR operation)
  • open vim editor (if the plugin cscope.vim is already installed the database previously created cscope.out is already attached). If not, attach the cscope.out with :cs add cscope.out
  • the cscope database is now ready to be used
  • use the list of the available commands (taken from the cscope.vim file:) with CTRL-\ :
    • ’s’ symbol: find all references to the token under cursor
    • ‘g’ global: find global definition(s) of the token under cursor
    • ‘c’ calls: find all calls to the function name under cursor
    • ’t’ text: find all instances of the text under cursor
    • ’e’ egrep: egrep search for the word under cursor
    • ‘f’ file: open the filename under cursor
    • ‘i’ includes: find files that include the filename under cursor
    • ’d’ called: find functions that function under cursor calls
Slavisa Jovanovic
Slavisa Jovanovic
Associate Professor (Maitre de conférence HDR)

My research interests include circuits and systems for AI and energy harvesting circuits.