how to auto load cscope.out in vim
Asked Answered
F

1

4

I want to auto load my cscope.out in the subdirectory of my project, so I add this scripts in my .vimrc, which is as follows:

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

it works at first. But every time when I trying to do:

:cs find c [tag]  

The search result will appear in the QuickFix List, but the file which contains the result can not be opened.

Any advice would be appreciated.

Ferreous answered 3/9, 2012 at 6:55 Comment(1)
Wikia article: vim.wikia.com/wiki/…Bambino
M
4

If you add a cscope.out make sure it to set the correct path prefix. Otherwise it will show you the result but cannot load the file.

example:

   cs add ../cscope.out ../

so you should change your script to

 ...
 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
 ...
Magnetograph answered 3/9, 2012 at 7:43 Comment(1)
Thanks for you reply.When I use :cs show I never notice that there is a prepend path there. And I found another way to make it works, when I generate cscope.file I use Relative path,When I change to use Absolute path in cscope.file it works very well. Thanks againFerreous

© 2022 - 2024 — McMap. All rights reserved.