2012-09-03 47 views
2

自動加載cscope.out中我想自動加載我cscope.out在我的項目的子目錄,所以我在.vimrc添加這個腳本,如下所示:如何在VIM

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列表中,但包含結果的文件無法打開。

任何意見,將不勝感激。

+0

Wikia文章:http://vim.wikia.com/wiki/Automatically_create_and_update_cscope_database你 –

回答

3

如果您添加一個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 
... 
+1

謝謝reply.When我使用 :cs顯示 我永遠不會注意到那裏有一個前置路徑。 我發現另一種方法使它工作,當我生成cscope.file 我使用相對路徑,當我改變使用cscope.file中的絕對路徑它工作得很好。 再次感謝 – Alan