LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1432|回复: 1

介绍个cscope插件, 项目任意子目录下开vim也能自动加载...

[复制链接]
发表于 2010-4-24 22:35:27 | 显示全部楼层 |阅读模式
翻遍了google上关于cscope的介绍, 也没找到这个设置技巧, 都是要求在项目根目录生成, 项目根目录打开vim...我懒啊....

麻烦, 于是自己憋着想写一个, 写了一半, 试了下去官网搜索, 竟然有!!

autoload_cscope.vim

http://www.vim.org/scripts/script.php?script_id=157

就像ctags设定set tags=tags; 在项目根目录生成总的tags, 任意子目录下即可自动加载...

用了这个插件, 项目根目录生成cscope.out, 随便钻到哪个项目子目录下, 自动正常加载, 正常搜索...

Tips:

  1. alias更方便
  2. alias cr='ctags -R --fields=+lS && cscope -Rbq'
  3. 这个全局变量设置下, 禁止这个插件自带的mapping
  4. let g:autocscope_menus=0
复制代码



config:
  1. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. " Cscope
  3. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

  4. " Use both cscope and ctag
  5. set cscopetag

  6. " Show msg when cscope db added
  7. set cscopeverbose

  8. " Use tags for definition search first
  9. set cscopetagorder=1

  10. " Use quickfix window to show cscope results
  11. set cscopequickfix=s-,c-,d-,i-,t-,e-

  12. " Cscope mappings
  13. nnoremap <C-w>\ :scs find c <C-R>=expand("<cword>")<CR><CR>
  14. nnoremap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
  15. nnoremap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
  16. nnoremap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
  17. nnoremap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
  18. nnoremap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
  19. nnoremap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
  20. nnoremap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
  21. nnoremap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
复制代码



problem:
我启用了cscope的quickfix, 但是它的反应和tags不一样, 不是开个quickfix窗口让你选, 而是直接跳到第一个, 虽然你可以自己打开quickfix窗口...绑定和手动都是这样...
发表于 2010-4-27 10:13:11 | 显示全部楼层
如果只是这个功能的话,不需要插件,直接在 .vimrc 中设置

if has("cscope")
    " add any database in current directory
    set nocsverb
    if filereadable("cscope.out")
        cs add cscope.out
    elseif filereadable("../cscope.out")
        cs add ../cscope.out
    elseif filereadable("../../cscope.out")
        cs add ../../cscope.out
    elseif filereadable("../../../cscope.out")
        cs add ../../../cscope.out
    endif
    set csverb
    set csto=0
endif

就可以了嘛,如果还想多搜索几层,就再加几个 else if 搞定。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表