vim + taglist + ctags + cscope 简单使用

来源:互联网 发布:痘印 红 知乎 编辑:程序博客网 时间:2024/05/20 02:28

vim + taglist + ctags + cscope 简单使用

    博客分类: 
  • linux
vimtaglistctagscscope

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
原创粉丝点击