为什么仅在第二次打开VIM之后才启用自动加载cscope.out
我要做的是每次打开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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在“ AutoCommand”块中,您将AutoComands添加到默认的AutoCommand组中。它们将在稍后执行,当您编辑
*。py
文件或其他任何内容时。此时,没有创建数据库。在“ cscope”块中,您指向数据库 cscope ,但没有创建数据库。
vimrc
来源后,加载了*。py
文件并创建了数据库,但是负责cscope
设置的代码已经运行SOCSCOPE
不知道您的数据库。下次运行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 thecscope
setup has already run socscope
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 andcscope
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()
.