vim插件之cscope的安装与配置

本文参考自:

http://easwy.com/blog/archives/advanced-vim-skills-cscope/

http://blog.csdn.net/dengxiayehu/article/details/6330200

http://blog.csdn.net/daofengdeba/article/details/7606616

插件介绍:

       cscope是用来查看源代码的工具,它具有纯正的Unix血统,最早由贝尔实验室为PDP-11计算机开发。Cscope曾是AT&T官方Unix分发版本的一部分,并被用来管理涉及2000万行代码的项目。

       cscope可以用来查询某个函数或者标签在哪里出现过。

插件安装:

1、从https://sourceforge.net/projects/cscope/files/cscope/下载最新版本的cscope;

2、解压后进行三板斧操作:./configure > make > make install。

在第2步中注意一下,我是用centOS操作的,当我make时出现"build.c:52:20: 致命错误:curses.h:没有那个文件或目录"的错误,这时需要在原处执行一下:

yum install ncurses-devel

然后再进行三板斧操作就行了。

插件配置:

1、生成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目录

2、在~/.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>

插件用法:

       在工程的根目录下用vim进入一个.c文件,然后在命令行模式输入

:cs find g 函数名

就会显示该函数在哪里出现过,如图:

图1

图2

关于cscope的用法:

: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的链接

 

posted @ 2017-03-16 21:30  willsonli  阅读(1486)  评论(0编辑  收藏  举报