如何在vim中自动加载cscope.out

如何在vim中自动加载cscope.out,vim,cscope,Vim,Cscope,我想在我的项目的子目录中自动加载我的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 fileread

我想在我的项目的子目录中自动加载我的
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]  
搜索结果将显示在快速修复列表中,但无法打开包含搜索结果的文件


任何建议都将不胜感激。

如果您添加了
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
 ...

感谢您的回复。当我使用:cs show时,我从未注意到那里有一个前置路径。我找到了另一种方法使它工作,当我生成cscope.file时,我使用相对路径,当我在cscope.file中更改为使用绝对路径时,它工作得非常好。再次感谢维基的一篇文章: