在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
這樣就不需要在子目錄下還要手動添加數據庫文件了 :)