Cscope

首先建立.vim/plugin資料夾
http://cscope.sourceforge.net/cscope_maps.vim放進去

在你想建立所有搜尋檔案的目錄下,接著執行cscope -R -q
可以看到以下畫面
Cscope version 15.5 Press the ? key for
help

Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
你可以找尋所要的檔案或是字串
搜尋結果會在上面列出來,按enter可以進入編輯檔案:q可以在回到此畫面

在編輯檔案時,cscope的所有指令都是以Ctr+\為開頭
把游標移到你想要搜尋的字串上
可以下以下的指令
c: Find functions calling this function
d: Find functions called by this function
e: Find this egrep pattern
f: Find this file
g: Find this definition
i: Find files #including this file
s: Find this C symbol
t: Find assignments to
另外Ctrl+t是回到你上一次查尋的地方,Ctrl+]則是再跳回
最後Ctrl+d就是結束程式

在vim下
:cs find e xxxx
基本使用大概是這樣

cscope pluging for vim

1) First install cscope if you haven't had it
$ sudo apt-get install cscope
2) Download cscope_map.vim and put it under your $HOME/.vim/plugin directory (or in any other 'plugin' subdirectory in your 'runtimepath')
3) Build a cscope index file for support of C++ tags
find $YourCodeDirectory/ -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" > $YourCodeDirectory/cscope.files
cscope -Rbq
(R is for recursively search subdirectories for source files; b for building the database not to launch cscope itself; q for faster symbol lookup)

if you should use absolute path names so that you don't have to launch vim in the same directory as the cscope database
4) Set the $CSCOPE_DB env variable to point to the cscope database you would like to use
One way is to put it in your .bashrc file, like
#
# added to specify the cscope database to use
#
export CSCOPE_DB=$YourCodeDirectory/cscope.out

Language support

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License