在Vim中使用cscope

在vim中搜索

:cs find {querytype} {name}

{querytype}:

0 or s: Find this C symbol

1 or g: Find this difinition

2 or d: Find functions called by this function

3 or c: Find functions calling this function

4 or t: Find this text string

6 or e: Find this egrep pattern

7 or f: Find this file

8 or i: Find files #including this file


使用cscope碰到的问题

1. E568: duplicate cscope database not added

根据提示,cscope数据库重复添加了,我使用的是vim7.2版本,而这个版本在已经支持cscope,并在它的配置文件中开启了cscope功能

$ vi /etc/vimrc 

 32 if has("cscope") && filereadable("/usr/bin/cscope")
 33    set csprg=/usr/bin/cscope
 34    set csto=0
 35    set cst
 36    set nocsverb
 37    " add any database in current directory
 38    if filereadable("cscope.out")
 39       cs add cscope.out
 40    " else add database pointed to by environment
 41    elseif $CSCOPE_DB != ""
 42       cs add $CSCOPE_DB
 43    endif
 44    set csverb
 45 endif

然后,我们给vim添加了一个插件,cscope_maps.vim, 这个文件主要作用是作一些快捷键映射,免去了输入命令的麻烦,但文件一直没有更新,里面只提及vim7以下的配置方法,在里面有如上所示相同的代码,所以导致了重复添加数据库的冲突

$ vi ~/.vim/plugin/cscope_maps.vim 

 40     " add any cscope database in current directory
 41     if filereadable("cscope.out")
 42         cs add cscope.out  
 43     " else add the database pointed to by environment variable 
 44     elseif $CSCOPE_DB != ""
 45         cs add $CSCOPE_DB
 46     endif

解决冲突的方法很简单,注释掉这些行便可以了

 

2. E567: no cscope connections

根据提示表示没有添加数据库(cscope.out),指定该文件便是了

:cs add $CSCOPE_DB

出现这种问题的原因很简单,就是当前目录下找不到cscope.out这个文件。当一个工程包含子目录的时候,我们一般是在顶层目录使用cscope -Rb建立数据库的,如果我们没有导入CSCOPE_DB这个环境变量的话,我们在子目录下vim打开一个文件便会出现E567问题,这显然很不方便。所以我们需要添加这个环境变量

$ export CSCOPE_DB=/yourproject/cscope.out

这样就不需要在子目录下还要手动添加数据库文件了 :)

 


posted @ 2012-03-12 13:04  neil90  阅读(15173)  评论(2编辑  收藏  举报