cscope在vim中不能向ctags一样自动的向上递归的查找索引数据库,一般的解法是手动的添加目录寻找,但是那样既丑陋,又费事情,所以我就把那个重新写了一下
" add any cscope database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add the database pointed to by environment variable
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
" find cscope.out or cscope/cscope.out
else
let cscope_file = findfile("cscope.out", ";/home/lelouch")
if !empty(cscope_file) && filereadable(cscope_file)
exe "cs add " . cscope_file
else
let cscope_file = findfile("cscope/cscope.out", ";/home/lelouch")
if !empty(cscope_file) && filereadable(cscope_file)
exe "cs add " . cscope_file
endif
endif
endif
这只是cscope_maps.vim中的一小部分,我就改了这一部分.增添的内容主要是查找cscope.out或者在cscope目录下的cscope.out(我喜欢后者,比较干净)
再附上生成数据库的脚本,写的很简陋(都是生成在项目的cscope目录下的.)
生成cscope索引的文件(cscope.files)
#!/bin/bash
cd $1
PROJ_PATH=`pwd`
if [ ! -x "cscope" ]; then
mkdir cscope
fi
find $PROJ_PATH -name "*.[chsS]" -o -name "*.cpp" > cscope/cscope.files
生成cscope数据库
#!/bin/bash
cd $1/cscope
cscope -bqk -i cscope.files
生成cscope数据库的时候,cscope不会从头生成的,只会生成那些变动过的文件,所以我们平时只需生成数据库即可了