cscope使用简介

来源:互联网 发布:网络的危害英语作文 编辑:程序博客网 时间:2024/06/05 15:18
cscope最早是由一位Joe Steffen的开发者,为了方便自己的工作而开发的。后来,在PDP-11上开发一项大工程时,进行改进。最后是在2000年由SCO公司开源。http://cscope.sourceforge.net/cscope主要是和vim搭配使用,主要的作用是查找函数、宏、变量或者字符串的引用。类似ctags但是更强大。安装很简单,Ubuntu可以使用apt-get install安装,centos可以使用yum install安装,也可以下载安装包,敲./configure   make   make install安装。使用也比较方便,首先,为你的代码生成数据库cscope -Rbqk-R:为当前目录下所有子目录创建数据库-b:生成数据库之后不启动自带的查询界面-q:生成cscope.in.out和cscope.po.out,加快搜索速度-k:跳过/usr/include目录执行完毕之后,当前目录会多出三个文件cscope.out          //生成的符号索引cscope.in.outcscope.po.outcscope支持8种查询:s:查找C语言符号,即函数名,宏,变量等g:查找函数,宏,变量等定义的位置,相当于转到定义d:查找本函数调用的函数c:查找调用本函数的函数t:查找指定的字符串e:查找egrep功能f:查找并打开文件i:查找包含本文件的文件在vim中使用cscope有两种方法:1、不用配置vimrc文件,直接使用命令:cs f(ind) g fun2、写入vimrc文件,可以定义快捷键,例如:Ctrl + \ + gvimrc配置可如下参考

if has(“cscope”)

set csprg=/usr/bin/cscopeset cstset cscopetagset csto=0set nocsverbif filereadable("cscope.out")    cs add cscope.outelseif $CSCOPE_DB != ""    cs add $CSCOPE_DBendifset csverbset cscopeverbosenmap <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>nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR><CR>nmap <C-@>g :scs find g <C-R>=expand("<cword>")<CR><CR>nmap <C-@>c :scs find c <C-R>=expand("<cword>")<CR><CR>nmap <C-@>t :scs find t <C-R>=expand("<cword>")<CR><CR>nmap <C-@>e :scs find e <C-R>=expand("<cword>")<CR><CR>nmap <C-@>f :scs find f <C-R>=expand("<cfile>")<CR><CR>nmap <C-@>i :scs find i <C-R>=expand("<cfile>")<CR><CR>nmap <C-@>d :scs find d <C-R>=expand("<cword>")<CR><CR>nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>nmap <C-@><C-@>i :vert scs find i <C-R>=expand("<cfile>")<CR><CR>nmap <C-@><C-@>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>

endif

注:查找包含本文件的快捷键中,大部分网上版本使用nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>但是我的计算机提示“找不到匹配的结果”,修改为上述方式可行综上,基本的cscope使用已经介绍完了,在使用过程中,需要特别注意的是,ctrl+\是同时按下,然后紧接着按g或者其他键,不能三个键同时按下。
原创粉丝点击