1. 程式人生 > >vim插件cscope使用方法

vim插件cscope使用方法

att don ace 查找 linu 某個文件 cas 搜索 管理

一、安裝cscope

安裝方式比較多樣,可以在各自linux軟件管理工具中安裝,也可以去官網下載安裝。

sudo apt-get install cscope

二、插件安裝

這裏選擇的是Vundle來管理vim插件,所以只需要在.vimrc中添加Plugin ‘brookhong/cscope.vim‘,然後執行:PluginInstall就搞定了。

三、生成標記庫

cscope在執行過程中實際上是通過掃描標記庫來首先找到標記以及標記的位置,從而實現跳轉的,因此首先需要為個人的代碼項目生成一個完整的標記庫。

[email protected]:~/work_space/KStoreCode/Kstore> cscope --help
Usage: cscope [
-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir] [-p number] [-P path] [-[0-8] pattern] [source files] -b Build the cross-reference only. -C Ignore letter case when searching. -c Use only ASCII characters in the cross-ref file (dont compress). -d Do not update the cross-reference.
-e Suppress the <Ctrl>-e command prompt between files. -F symfile Read symbol reference lines from symfile. -f reffile Use reffile as cross-ref file name instead of cscope.out. -h This help screen. -I incdir Look in incdir for any #include files. -i namefile Browse through files listed in
namefile, instead of cscope.files -k Kernel Mode - dont use /usr/include for #include files. -L Do a single search with line-oriented output. -l Line-oriented interface. -num pattern Go to input field num (counting from 0) and find pattern. -P path Prepend path to relative file names in pre-built cross-ref file. -p n Display the last n file path components. -q Build an inverted index for quick symbol searching. -R Recurse directories for files. -s dir Look in dir for additional source files. -T Use only the first eight characters to match against C symbols. -U Check file time stamps. -u Unconditionally build the cross-reference file. -v Be more verbose in line mode. -V Print the version number. Please see the manpage for more information.

參數比較多,但一般來說cscope -Rbq就夠用了,R表示遞歸,默認cscope會進入搜索頁面,b可以不進入這個頁面,q會生成索引,加快查找速度。

在代碼根目錄下使用,建立數據庫

cscope -Rbq

四、在vim中添加標記庫

上面執行過後會生成三個文件,cscope.out就是生成的數據庫,cscope.in.out和cscope.po.out是q控制對應的索引。使用vim打開項目中某個文件,然後cscope add cscope.out就能夠識別該數據庫,方便後續使用。

五、vim中使用cscope查找

使用cscope find s xxx來進行cscope的使用即可。s是參數,其他參數及意義如下:

s: 查找C語言符號,即查找函數名、宏、枚舉值等出現的地方
g: 查找函數、宏、枚舉等定義的位置,類似ctags所提供的功能
d: 查找本函數調用的函數
c: 查找調用本函數的函數
t: 查找指定的字符串
e: 查找egrep模式,相當於egrep功能,但查找速度快多了
f: 查找並打開文件,類似vim的find功能
i: 查找



vim插件cscope使用方法