生成cscope数据库,你代码所在的父目录下运行:
cscope -Rbkq
会生成三个文件:cscope.out, cscope.in.out, cscope.po.out。其中:
- R 表示把所有子目录里的文件也建立索引;
- b 表示cscope不启动自带的用户界面,而仅仅建立符号数据库;
- q 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度;
- k 生成索引文件时,不搜索/usr/include目录;
在vimrc文件中配置:
if has("cscope")
set csprg=/usr/local/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
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 find s ------ 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
:cs find g ------ 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
:cs find d ------ 查找本函数调用的函数
:cs find c ------ 查找调用本函数的函数
:cs find t ------ 查找指定的字符串
:cs find e ------ 查找egrep模式,相当于egrep功能,但查找速度快多了
:cs find f ------- 查找并打开文件,类似vim的find功能
:cs find i ------- 查找包含本文件的文件
:help cscope ---查看帮助
:cscope add 路径-----添加cscope数据库路径
:cs kill {num|partial_name}-----杀掉一个cscope数据库
:cs reset--------重新初始化所有的cscope数据库
:cs show--------显示cscope的链接
源意补充:
'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
update脚本:
#!/bin/bash
echo clear cscope.files
echo > cscope.files
echo
echo begin search files ++++++
esho 绝对路径
find 绝对路径 -name '*.cpp' -o -name '*.h' -o -name '*.cc' >> cscope.files
echo end search files ------
echo
echo "cscope -bkq -i cscope.files"
cscope -bkq -i cscope.files