1. 安装ctags和cscope
sudo apt-get install -y exuberant-ctags cscope
2. vimrc中的配置
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " cscope setting " " cscope 使用方法: " -R: 在生成索引文件时,搜索子目录树中的代码 " -b: 只生成索引文件,不进入cscope的界面 " -q: 生成cscope.in.out和cscope.po.out文件,加快索引 " -k: 在生成索引文件时,不搜索/usr/include目录 " -i: 保存文件列表的文件名不是cscope.files时需此项,可使用“-” " -I dir: 在-I选项指出的目录中查找头文件 " -u: 扫描所有文件,重新生成交叉索引文件 " -C: 在搜索时忽略大小写 " -P path: 在以相对路径表示的文件前加上的path, " 可不切换至数据库文件所在目录亦可使用 " " cscope find的用法: " cs find c|d|e|f|g|i|s|t name " 0 或 s 查找本 C 符号(可以跳过注释) " 1 或 g 查找本定义 " 2 或 d 查找本函数调用的函数 " 3 或 c 查找调用本函数的函数 " 4 或 t 查找本字符串 " 6 或 e 查找本 egrep 模式 " 7 或 f 查找本文件 " 8 或 i 查找包含本文件的文件 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if has("cscope") if has("unix") set cscopeprg=/usr/bin/cscope elsei has("win16") || has("win32") " path ocscope endif set cscopetag " 使用<C-]>进行跳转 set cscopetagorder=1 " :cscope find g foo,然后:tselect foo set nocscopeverbose " 添加数据库时不显示详细信息 " 添加cscope.out if filereadable(expand("%:p:h") . "/" . "cscope.out") let cscope_file = expand("%:p:h") . "/" . "cscope.out" cs add cscope_file elseif filereadable(expand("%:p:h") . "/../" . "cscope.out") let cscope_file = expand("%:p:h") . "/../" . "cscope.out" cs add cscope_file elseif filereadable(expand("%:p:h") . "/../../" . "cscope.out") let cscope_file = expand("%:p:h") . "/../../" . "cscope.out" cs add cscope_file elseif filereadable(expand("%:p:h") . "/../../../" . "cscope.out") let cscope_file = expand("%:p:h") . "/../../../" . "cscope.out" cs add cscope_file elseif filereadable(expand("%:p:h") . "/../../../../" . "cscope.out") let cscope_file = expand("%:p:h") . "/../../../../" . "cscope.out" cs add cscope_file endif " 添加tags(can't use set tags in this section) if filereadable(expand("%:p:h") . "/" . "tags") let TAGSFILEN = expand("%:p:h") . "/" . "tags" let &tags = expand(&tags . "," . TAGSFILEN) elseif filereadable(expand("%:p:h") . "/../" . "tags") let TAGSFILEN = expand("%:p:h") . "/../" . "tags" let &tags = expand(&tags . "," . TAGSFILEN) elseif filereadable(expand("%:p:h") . "/../../" . "tags") let TAGSFILEN = expand("%:p:h") . "/../../" . "tags" let &tags = expand(&tags . "," . TAGSFILEN) elseif filereadable(expand("%:p:h") . "/../../../" . "tags") let TAGSFILEN = expand("%:p:h") . "/../../../" . "tags" let &tags = expand(&tags . "," . TAGSFILEN) elseif filereadable(expand("%:p:h") . "/../../../../" . "tags") let TAGSFILEN = expand("%:p:h") . "/../../../../" . "tags" let &tags = expand(&tags . "," . TAGSFILEN) endif set cscopeverbose " 添加数据库时显示详细信息 endif
3. 生成tags和cscope.out的脚本
#!/bin/bash - #=============================================================================== # # FILE: cstags # # USAGE: ./cstags # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: linkscue(scue), # ORGANIZATION: # CREATED: 2013年08月02日 16时44分12秒 HKT # REVISION: --- #=============================================================================== echo "正在生成tags文件" /usr/bin/ctags -R --fields=+lS . if [[ $? == 0 ]]; then echo "生成tags文件成功" echo "$(readlink -f tags)" else echo "生成tags文件失败" fi echo "正在生成cscope.out" find . -name "*.s" -o -name ".S" -o -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.cc" > cscope.files /usr/bin/cscope -Rbq if [[ $? == 0 ]]; then echo "生成cscope.out成功" echo "$(readlink -f cscope.out)" else echo "生成cscope.out失败" fi