为什么仅在第二次打开VIM之后才启用自动加载cscope.out

发布于 2025-01-27 13:36:20 字数 1614 浏览 2 评论 0原文

我要做的是每次打开VIM时都基于不同的文件类型创建一个新的CSCOPE数据库,然后自动加载cscope.out

我编辑我的.vimrc,基于本文:如何自动加载cscope.out in Vim

但它仅自动加载cscope.out第二次我打开vim,第一次打开vim,它总是显示no cscope connection

我应该更改什么?

这是我的设置:

if !filereadable("cscope.out")
    autocmd BufRead,BufNewFile *.py !find / -name "*.py" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.java !find / -name "*.java" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.c !find / -name "*.c" -o -name "*.h" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.cpp !find / -name "*.cpp" -o -name "*.hpp" -o -name "*.h" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.hpp !find / -name "*.cpp" -o -name "*.hpp" -o -name "*.h" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
endif

" setting location of cscope db & cscopetag
let CSCOPE_DB="~/cscope.out"                
                                                                              
if has("cscope")
"   set csprg=/usr/local/bin/cscope
    set csto=0
    set cst
    set nocsverb
    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
    " else add database pointed to by environment
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
    set csverb
endif

What I want to do is to create a new cscope database based on different file types every time I open vim, and then automatically load cscope.out

I edit my .vimrc, based on this article: how to auto load cscope.out in vim

But it only autoloads cscope.out the second time I open vim, the first time I open vim, it always show no cscope connection

What should I change?

Here is my settings:

if !filereadable("cscope.out")
    autocmd BufRead,BufNewFile *.py !find / -name "*.py" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.java !find / -name "*.java" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.c !find / -name "*.c" -o -name "*.h" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.cpp !find / -name "*.cpp" -o -name "*.hpp" -o -name "*.h" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
    autocmd BufRead,BufNewFile *.hpp !find / -name "*.cpp" -o -name "*.hpp" -o -name "*.h" > ~/cscope.files; cscope -Rbq -i ~/cscope.files
endif

" setting location of cscope db & cscopetag
let CSCOPE_DB="~/cscope.out"                
                                                                              
if has("cscope")
"   set csprg=/usr/local/bin/cscope
    set csto=0
    set cst
    set nocsverb
    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
    " else add database pointed to by environment
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
    set csverb
endif

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走走停停 2025-02-03 13:36:20

在“ AutoCommand”块中,您将AutoComands添加到默认的AutoCommand组中。它们将在稍后执行,当您编辑*。py文件或其他任何内容时。此时,没有创建数据库。

在“ cscope”块中,您指向数据库 cscope ,但没有创建数据库。

vimrc来源后,加载了*。py文件并创建了数据库,但是负责cscope设置的代码已经运行SO CSCOPE不知道您的数据库。

下次运行vim时,数据库已经存在,因为它是在上一个运行期间创建的,因此设置cscope的代码按预期完成其作业,并且cscope get适当的数据库。

您应该能够通过推迟cscope在创建数据库之后的上解决问题,这听起来像是的完美用例:help job_start( )

In the "autocommand" block, you add autocommands to the default autocommand group. They will be executed later, when you edit a *.py file or whatever. At this point, no database is created.

In the "cscope" block, you point cscope to a database but no database has been created.

After your vimrc is sourced, the *.py file is loaded and the database is created but the code in charge of the cscope setup has already run so cscope doesn't know about your database.

The next time you run Vim, the database is already there because it has been created during the previous run, so code that sets up cscope does its job as expected and cscope gets a proper database.

You should be able to solve your problem by postponing the cscope step to after the database has been created, which sounds like a perfect use case for :help job_start().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文