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
cscopeif not already (under fedorasudo 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 namedcscope.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.fileswherecscope.filesis previously created with find . -name "*.cpp" -o -name "*.hpp" -o "*.h" >> cscope.filesfor instance (the first “-o” is forORoperation)
- if you want to use recursive search during the database creation
- open
vimeditor (if the plugincscope.vimis already installed the database previously createdcscope.outis already attached). If not, attach thecscope.outwith:cs add cscope.out - the cscope database is now ready to be used
- use the list of the available commands (taken from the
cscope.vimfile:) withCTRL-\:- ’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