0

I am trying to use the CCTree plugin for vim, but when I try to add the following line to my vimrc to autoload the cscope database for CCTree every time vim is opened, I get an error. This is the command copied straight from the CCTree website (https://sites.google.com/site/vimcctree/faq):

autocmd VimEnter * if filereadable('cscope.out') | CCTreeLoadDB cscope.out | endif

The error I get is:

Error detected while processing VimEnter Auto commands for "*":
E172: Only one file name allowed:  CCTreeLoadDB cscope.out | endif

I would have assumed this would work as it is straight from the CCtree website but I don't know how to debug this as I've barely used/edited my vimrc file. Any help would be appreciated.

4

2 回答 2

2

似乎CCTreeLoadDB认为|andendif是它命令的参数而不是if.

将它包装在一个函数中,以便if语句位于多行上,这样就可以autocmd工作了。

function! LoadCCTree()
    if filereadable('cscope.out')
        CCTreeLoadDB cscope.out
    endif
endfunc
autocmd VimEnter * call LoadCCTree()

工作一个不使用函数包装器的班轮。将其包装CCTreeLoadDB在 exec 中,以免混淆。

autocmd VimEnter * if filereadable('cscope.out') | exec "CCTreeLoadDB 'cscope.out'" | endif

请参阅 Ingo Karkat 的回答,了解为什么CCTreeLoadDB不使用|

于 2013-06-28T00:36:44.470 回答
1

您只能链接使用 定义的命令-bar。如果该:CCTreeLoadDB命令只接受一个文件名,那么修改它是安全的:

:command! -bar ... CCTreeLoadDB ...

您可以将这样的建议发送给插件的作者。同时,最好将命令包装在:execute.

于 2013-06-28T06:18:46.593 回答