安裝方式比較多樣,能夠在各自linux軟件管理工具中安裝,也能夠去官網下載安裝。linux
sudo apt-get install cscope
這裏選擇的是Vundle來管理vim插件,因此只須要在.vimrc中添加Plugin 'brookhong/cscope.vim',而後執行:PluginInstall就搞定了。數據庫
cscope在執行過程當中其實是經過掃描標記庫來首先找到標記以及標記的位置,從而實現跳轉的,所以首先須要爲我的的代碼項目生成一個完整的標記庫。vim
binresist@binresist:~/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 (don't 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 - don't 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
上面執行事後會生成三個文件,cscope.out就是生成的數據庫,cscope.in.out和cscope.po.out是q控制對應的索引。使用vim打開項目中某個文件,而後cscope add cscope.out就可以識別該數據庫,方便後續使用。ui
使用cscope find s xxx來進行cscope的使用便可。s是參數,其餘參數及意義以下:spa
s: 查找C語言符號,即查找函數名、宏、枚舉值等出現的地方
g: 查找函數、宏、枚舉等定義的位置,相似ctags所提供的功能
d: 查找本函數調用的函數
c: 查找調用本函數的函數
t: 查找指定的字符串
e: 查找egrep模式,至關於egrep功能,但查找速度快多了
f: 查找並打開文件,相似vim的find功能
i: 查找