vim + taglist + ctags + cscope 简单使用

ctags用来跳转, taglist用来列出当前文件的变量, 函数, 宏. cscope用来查找符号



一 使用ctags


1 在源码目录创建tag文件

cd /home/kenby/project/nginx-1.0.0/src

ctags -R


2 打开一个文件

gvim core/ngx_string.c

把光标移到变量名或函数名上,然后按下"Ctrl-]"。用"Ctrl-o"退回原来的地方。


二 使用taglist


打开一个文件, 并输入命令, vim就会产生一栏显示该文件的变量和函数

gvim core/ngx_string.c

:Tlist



三 使用cscope


1 生成 cscope.files

cd /

find /home/kenby/project/nginx-1.0.0/src -name '*.c' -o -name "*.h" > /home/kenby/project/nginx-1.0.0/src/cscope.files


2 生成 cscope.out

cd /home/kenby/project/nginx-1.0.0/src

cscope -b -q -k

这样在源码目录下产生一些 .out 索引文件


3 打开一个文件

gvim core/ngx_string.c


4 添加索引

:cs add cscope.out


5 输入下列命令, 试用cscope强大的查找功能

:cs f c ngx_log_error      查找此函数被哪些函数调用过

:cs f d ngx_log_error      查找此函数调用了哪些函数

:cs f g ngx_log_error      查找变量名或函数名的定义处

:cs f s  ngx_log_error     查找该符号出现的地方

:cs f t  variable              查找给该变量赋值的地方



四 vimrc配置文件

使用cscope, 每次都输入那么长的命令, 实在很伤手, 在vimrc配置一些快捷键:


if has("cscope")

  set csprg=/usr/bin/cscope

  set csto=1

  set cst

  set nocsverb

  " add any database in current directory

  if filereadable("cscope.out")

      cs add cscope.out

  endif

  set csverb

endif


nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>

nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>

nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>

nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>

nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>

nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>

nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>

nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值