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 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.files
wherecscope.files
is previously created with find . -name "*.cpp" -o -name "*.hpp" -o "*.h" >> cscope.files
for instance (the first “-o” is forOR
operation)
- if you want to use recursive search during the database creation
- open
vim
editor (if the plugincscope.vim
is already installed the database previously createdcscope.out
is already attached). If not, attach thecscope.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:) 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