vim插件cscope使用方法

1 安装cscope

安装方式比较多样,可以在各自linux软件管理工具中安装,也可以去官网下载安装。

2 插件安装

这里选择的是Vundle来管理vim插件,所以只需要在.vimrc中添加Plugin 'brookhong/cscope.vim',然后执行:PluginInstall就搞定了。

3 生成标记库

cscope在执行过程中实际上是通过扫描标记库来首先找到标记以及标记的位置,从而实现跳转的,因此首先需要为个人的代码项目生成一个完整的标记库。

binresist@binresist:~/work_space/KStoreCode/Kstore> cscope --help
Usage: cscope [-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir]
              [-p number] [-P path] [-[0-8] pattern] [source files]

              -b            Build the cross-reference only.
              -C            Ignore letter case when searching.
              -c            Use only ASCII characters in the cross-ref file (don't compress).
              -d            Do not update the cross-reference.
              -e            Suppress the <Ctrl>-e command prompt between files.
              -F symfile    Read symbol reference lines from symfile.
              -f reffile    Use reffile as cross-ref file name instead of cscope.out.
              -h            This help screen.
              -I incdir     Look in incdir for any #include files.
              -i namefile   Browse through files listed in namefile, instead of cscope.files
              -k            Kernel Mode - don't use /usr/include for #include files.
              -L            Do a single search with line-oriented output.
              -l            Line-oriented interface.
              -num pattern  Go to input field num (counting from 0) and find pattern.
              -P path       Prepend path to relative file names in pre-built cross-ref file.
              -p n          Display the last n file path components.
              -q            Build an inverted index for quick symbol searching.
              -R            Recurse directories for files.
              -s dir        Look in dir for additional source  files.
              -T            Use only the first eight characters to match against C symbols.
              -U            Check file time stamps.
              -u            Unconditionally build the cross-reference file.
              -v            Be more verbose in line mode.
              -V            Print the version number.

              Please see the manpage for more information.

参数比较多,但一般来说cscope -Rbq就够用了,R表示递归,默认cscope会进入搜索页面,b可以不进入这个页面,q会生成索引,加快查找速度。

4 在vim中添加标记库

上面执行过后会生成三个文件,cscope.out就是生成的数据库,cscope.in.out和cscope.po.out是q控制对应的索引。使用vim打开项目中某个文件,然后cscope add cscope.out就能够识别该数据库,方便后续使用。

5 vim中使用cscope查找

使用cscope find s xxx来进行cscope的使用即可。s是参数,其他参数及意义如下:

s: 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
g: 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
d: 查找本函数调用的函数
c: 查找调用本函数的函数
t: 查找指定的字符串
e: 查找egrep模式,相当于egrep功能,但查找速度快多了
f: 查找并打开文件,类似vim的find功能
i: 查找包含本文件的文件
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值