您的位置:首页 > 运维架构

Env:Cscope安装与配置

2016-05-07 20:52 417 查看

1. 介绍

Cscope是类似于ctags一样的工具,但可认为他是ctags的增强版。

2. 安装

sudo apt-get install cscope

通过源码安装,参照http://blog.csdn.net/hpwzd/article/details/7405401

3. 配置

在源码所在目录下,执行cscope -Rbkq 会生成三个文件:cscope.out/csope.in.out/cscope.po.out

在Vimrc中添加如下一段话,其中/usr/bin/cscope为可执行文件所在目录,如果没有vimrc,那就新建,可以通过whereis查看:

"......................................cscope...........................
if has("cscope")
set csprg=/usr/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
"....................................cscope replace
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>


使用方法是,同时按下Ctrl+@后松开按下's':

Ctrl+@-> s ---- 查找C语言符号,即查找函数名、宏、枚举值等出现的地方

Ctrl+@-> g ---- 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能

Ctrl+@-> d ---- 查找本函数调用的函数

Ctrl+@-> c ---- 查找调用本函数的函数

Ctrl+@-> t ---- 查找指定的字符串

Ctrl+@-> e ---- 查找egrep模式,相当于egrep功能,但查找速度快多了

Ctrl+@-> f ---- 查找并打开文件,类似vim的find功能

Ctrl+@-> i ---- 查找包含本文件的文

需要注意的是:

打开源文件需要在cscope.out路径下打开,如$ vi ./drivers/tty/serial/imx.c而不是到serial目录下执行$ vi imx.c.否则会出现找不到cscope.

查找进入新的文件后,退回去快捷键:Ctrl+t.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: