如何在Vim中自动加载cscope.out文件

4

我想要在项目的子目录中自动加载 cscope.out ,所以我在我的 .vimrc 中添加了以下脚本:

set cscopequickfix=s-,c-,d-,i-,t-,e-

if has("cscope")
    set csprg=/usr/bin/cscope
    set csto=1
    set cst
    set csverb
    set cspc=3
    "add any database in current dir
    if filereadable("cscope.out")
        cs add cscope.out
    "else search cscope.out elsewhere
    else
       let cscope_file=findfile("cscope.out", ".;")
        "echo cscope_file
        if !empty(cscope_file) && filereadable(cscope_file)
            exe "cs add" cscope_file
        endif      
     endif
endif

一开始它是可以工作的。但每次我尝试做以下操作时:

:cs find c [tag]  

搜索结果将会出现在“QuickFix List”中,但是包含结果的文件无法打开。
如有建议,请不吝赐教。

维基百科文章:http://vim.wikia.com/wiki/Automatically_create_and_update_cscope_database - Ciro Santilli OurBigBook.com
1个回答

4
如果您添加了一个cscope.out,请确保设置正确的路径前缀。否则它将显示结果但无法加载文件。
例如:
   cs add ../cscope.out ../

所以您应该更改您的脚本为:
 ...
 else
   let cscope_file=findfile("cscope.out", ".;")
   let cscope_pre=matchstr(cscope_file, ".*/")
   "echo cscope_file
   if !empty(cscope_file) && filereadable(cscope_file)
      exe "cs add" cscope_file cscope_pre
   endif
 ...

2
谢谢您的回复。当我使用:cs show命令时,我从未注意到那里有一个prepend路径。我发现另一种使它工作的方法是,在生成cscope.file文件时,我使用相对路径。当我改为在cscope.file中使用绝对路径时,它非常好用。再次感谢。 - Alan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接