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.

still.Learning
  • 1,185
  • 5
  • 13
  • 18

2 Answers2

2

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 |

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • That worked perfectly, thank you! They really should update their instructions for people like me who have very little experience with using the vimrc file. I went with the function method by the way (for future reference). – still.Learning Jun 28 '13 at 02:05
1

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.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324