一.安装
去Cscope的主页在http://cscope.sourceforge.net/下载cscope安装包。解压后进行安装:
.#:./configuer
#:make
#:make install
二.使用步骤
(1)vim必须先支持cscope,通过#vim --version grep 'cscope'命令来查看是否支持,如果不支持,需要重装vim
(2)为代码生成一个cscope数据库。在项目根目录运行下面的命令:
#cscope -Rbq
这个命令会生成三个文件:cscope.out, cscope.in.out, cscope.po.out。
其中cscope.out是基本的符号索引,后两个文件是使用”-q“选项生成的,可以加快cscope的索引速度。
Cscope在生成数据库中,在项目目录中未找到的头文件,会自动到/usr/include目录中查找,也可以是用参数组织从/usr/include目录中查找。
(3) 添加文件类型进入查找范围
find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" > cscope.files
(4) 建立数据库
cscope -R -b -i cscope.files
-q表示速度快, -R递归 -b表示只建立数据库, 但是不进入交互操作界面
如果想进入操作界面运行: cscope -d
(5) 添加数据库文件到cscopes搜索下 vim ~/.vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
三.查找命令
:cs f s ---- 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
:cs f g ---- 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
:cs f d ---- 查找本函数调用的函数
:cs f c ---- 查找调用本函数的函数
:cs f t ---- 查找指定的字符串
:cs f e ---- 查找egrep模式,相当于egrep功能,但查找速度快多了
:cs f f ---- 查找并打开文件,类似vim的find功能
:cs f i ---- 查找包含本文件的文
四. 跳转
Ctrl+] 将跳到光标所在变量或函数的定义处
Ctrl+T 返回
:set csto=0
‘csto’的值决定了|:cstag|执行查找的顺序。假如’csto’被设置为0,那么cscope数据将会被优先查找,假如cscope没有返回匹配项,然后才会查找tag文件。反之,则查找顺序相反。默认值是0。
参考:1. https://blog.csdn.net/clevercode/article/details/51379309
2.https://blog.easwy.com/archives/advanced-vim-skills-cscope/
3.https://blog.csdn.net/dengxiayehu/article/details/6330200
4.https://blog.csdn.net/magiclyj/article/details/79660259
5. https://blog.csdn.net/u011671986/article/details/79457036