cscope +vim configurations

本文详细介绍了如何解决vim7.2版本中cscope数据库重复添加的问题,并通过注释cscope_maps.vim插件内的相关代码段,避免了冲突。同时,解释了如何正确配置vim和cscope以实现高效的代码搜索。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. setroot

#!/bin/sh
export ROOT=`pwd`
echo "the root is [$ROOT]"
export CSCOPE_DB=$ROOT/cscope.out


this should be invoked by . setroot


2. cscope

cs.sh

#!/usr/bin/env bash

DBFILE="cscope.files"
DBFILE=$ROOT/$DBFILE


# cs.sh -b to build
# cs.sh to invoke

#echo name of script is $0
#echo first argument is $1
#echo second argument is $2
#echo number of arguments is $#

help ()
{
        echo "cs.sh -b to build"
        echo "cs.sh to invoke"
        echo ". setroot first"
}


build_database()
{

        find $PWD -name *.php > $DBFILE
        cscope -b -q -k -i $DBFILE
        CSCOPE_DB=$DBROOT/cscope.out
        DBFILE=$DBROOT/$DBFILE
        export CSCOPE_DB  DBFILE
}

# check ROOT setting
if [ -d $ROOT ]
then
        echo "the ROOT is $ROOT"
        CSCOPE_DB=$ROOT/cscope.out
        export CSCOPE_DB
        echo "CSCOPE_DB is $CSCOPE_DB"
else
        help
        exit 1
fi


if [ "$#" -eq 1 ]
then
        if [ "$1" == "-b" ]
        then
                echo "the command is involed using cs -b"
                build_database
        else
                help
                exit
        fi
else
        echo $CSCOPE_DB
        echo $DBFILE
        cscope -d -f $CSCOPE_DB -i $DBFILE
fi

alias cs="/bin/cs.sh"

3. vim plugin

use the http://cscope.sourceforge.net/large_projects.html

http://cscope.sourceforge.net/cscope_maps.vim

Put it into .vim/plugin/

issue:

Error detected while processing /root/.vim/plugin/cscope_maps.vim:
line   42:
E568: duplicate cscope database not added


1. E568: duplicate cscope database not added

根据提示,cscope数据库重复添加了,我使用的是vim7.2版本,而这个版本在已经支持cscope,并在它的配置文件中开启了cscope功能

$ vi /etc/vimrc 

 32 if has("cscope") && filereadable("/usr/bin/cscope")
 33    set csprg=/usr/bin/cscope
 34    set csto=0
 35    set cst
 36    set nocsverb
 37    " add any database in current directory
 38    if filereadable("cscope.out")
 39       cs add cscope.out
 40    " else add database pointed to by environment
 41    elseif $CSCOPE_DB != ""
 42       cs add $CSCOPE_DB
 43    endif
 44    set csverb
 45 endif

然后,我们给vim添加了一个插件,cscope_maps.vim, 这个文件主要作用是作一些快捷键映射,免去了输入命令的麻烦,但文件一直没有更新,里面只提及vim7以下的配置方法,在里面有如上所示相同的代码,所以导致了重复添加数据库的冲突

$ vi ~/.vim/plugin/cscope_maps.vim 

 40     " add any cscope database in current directory
 41     if filereadable("cscope.out")
 42         cs add cscope.out  
 43     " else add the database pointed to by environment variable 
 44     elseif $CSCOPE_DB != ""
 45         cs add $CSCOPE_DB
 46     endif

解决冲突的方法很简单,注释掉这些行便可以了





--

make two lines of prompts:

export PS1="\u@\h:\w\n#"


VIM 其他的设置

http://www.netingcn.com/tag/vim

http://blog.csdn.net/dingnning/article/details/7189862






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值