Question

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.

Was it helpful?

Solution

Its seems that CCTreeLoadDB think that the | and endif are parameters to it commands instead of the separator to the if.

Wrapping it in a function so that the if statement is on multiple line makes the autocmd work.

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

Working one liner that doesn't use a function wrapper. Wrap the CCTreeLoadDB in an exec so it doesn't get confused.

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

See Ingo Karkat's answer for why CCTreeLoadDB does not work with |

OTHER TIPS

You can only chain commands that are defined with -bar. If the :CCTreeLoadDB command just takes a filename, it would be safe to modify it:

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

You could send such a suggestion to the plugin's author. In the meantime, it's best to wrap the command in :execute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top