1、/usr/share/vim/vimrc 的内容如下 :
set showmatch
set incsearch
set mouse=a
set cindent
set hlsearch
set tabstop=4
set softtabstop=4
set shiftwidth=4
set nu
set tags=tags;
set autochdir
let Tlist_Show_One_File = 1 " -------只允许taglist显示一个文件的信息
let Tlist_Exit_OnlyWindow = 1 " ---------当显示taglist信息的窗口是最后一个时,退出vim
let Tlist_Process_File_Always = 1 " -----时时更新taglist
let Tlist_Auto_Open = 1
"cscope插件热键
nmap cs :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap cg :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap cc :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap cd :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap ct :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap ce :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap cf :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap ci :cs find i ^<C-R>=expand("<cfile>")<CR><CR>
" add any cscope database in current directory
if has("cscope")
set cscopetag
set csto=0
if filereadable("cscope.out") " 若当前目录下存在cscope数据库,添加该数据库到vim
cs add cscope.out
elseif $CSCOPE_DB != "" " 否则只要环境变量CSCOPE_DB不为空,则添加其指定的数据库到vim
cs add $CSCOPE_DB
endif
endif
2、/bin/cscope.sh 的内容如下:(在源码要目录下执行“source /bin/cscope.sh”即可生成cscope需要的索引,参考:cscope的快速初始化和使用技巧)
#!/bin/bash
DIR=`pwd`
update=1
change=0
while getopts "d:uc" opt;
do
case $opt in
d)
DIR=$OPTARG
;;
u)
update=1
;;
c)
change=1
;;
?)
echo "invaild option!"
exit 1
esac
done
cd ${DIR}
if [ 1 -eq ${change} ]; then
echo "change project cscope database!"
res=$(find ${DIR} -name cscope.out)
if [ "x"${res} = "x" ]; then
echo "Not found cscope database, generate cscope database!"
find ${DIR} -name "*.[h|c|cc|cpp|hh]" > cscope.files
cscope -bkq -i cscope.files
#ctags -R *
export CSCOPE_DB=${DIR}/cscope.out
else
echo "Found cscope database:${res}, just change CSCOPE_DB env!"
export CSCOPE_DB=${res}
fi
elif [ 1 -eq ${update} ]; then
echo "udpate project cscope database!"
find ${DIR} -name "*.[h|c|cc|cpp|hh]" > cscope.files
cscope -bkq -i cscope.files
#ctags -R *
export CSCOPE_DB=${DIR}/cscope.out
fi
echo CSCOPE_DB_PATH=${CSCOPE_DB}