vim


符号查找和跳转

cscope

建立数据库
常用
cscope -Rqb

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.
              只构建数据库,不进入cscope会话
-I incdir     Look in incdir for any #include files.
-k            Kernel Mode - don't use /usr/include for #include files.
-q            Build an inverted index for quick symbol searching.
              生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
-R            Recurse directories for files.
              包含子目录
-s dir        Look in dir for additional source  files.

查找

cscope commands:
add  : Add a new database             (Usage: add file|dir [pre-path] [flags])
find : Query for a pattern            (Usage: find a|c|d|e|f|g|i|s|t name)
       a: Find assignments to this symbol ( 查找对符号的赋值 )
如 :cs find a main
Cscope tag: main
   #   line  filename / context / line
   1    395  src/http/modules/ngx_http_rewrite_module.c <>
             sc.main = regex;
   2   2419  src/http/ngx_http_core_module.c <>
             sr->main = r->main;
   3    615  src/http/ngx_http_request.c <>
             r->main = r;

       c: Find functions calling this function 查找某函数或宏被调用的位置
Cscope tag: ngx_align_ptr
   #   line  filename / context / line
   1    122  src/core/ngx_crc32.c <>
             p = ngx_align_ptr(p, ngx_cacheline_size);
   2     43  src/core/ngx_hash.c <>
             elt = (ngx_hash_elt_t *) ngx_align_ptr(&elt->name[0] + elt->len,

       d: Find functions called by this function 查找某函数调用的函数

       e: Find this egrep pattern
       f: Find this file
       g: Find this definition
       i: Find files #including this file  
       s: Find this C symbol
       t: Find this text string

ctrl+d 退出 cscope

vim 中使用cscope,
vim 实现了回调cscope的函数,所以不需要插件。
增加配置

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
  set csto=0 " 0:优先使用cscope.file查找,1:优先使用tags查找
  set cst    " 把cscope.file当tags文件使用,即可以用 找定义
  set nocsverb
  " add any database in current directory
  if filereadable("cscope.out")
      cs add cscope.out
  endif
  set csverb

nmap s :cs find s =expand("")
nmap g :cs find g =expand("")
nmap c :cs find c =expand("")
nmap t :cs find t =expand("")
nmap e :cs find e =expand("")
nmap f :cs find f =expand("")

endif

大项目中使用cscope
http://cscope.sourceforge.net/large_projects.html