1

I have created a new command

command! Tags execute '!GTAGSFORCECPP=1 gtags' | cscope kill -1 | cscope add GTAGS

However, for some reason cscope add GTAGS doesn't execute when I execute :Tags.

Can someone explain what is the problem?

Any help is appreciated.

  • 1
    Vim has an odd way of parsing commands with optional arguments. Wrapping the two cscope commands in execs might produce better results. – Sato Katsura Oct 9 '15 at 6:04
2

Your problem is that :command does not (by default) accept the use of bars, as explaind in :h :bar. You may circumvent this by using the -bar option, see :h :command-bar:

command! -bar Tags execute '!GTAGSFORCECPP=1 gtags'
    \ | cscope kill -1
    \ | cscope add GTAGS

You can also wrap the functionality in a function, like this:

command! Tags :call s:tags()

function! s:tags()
  execute '!GTAGSFORCECPP=1 gtags' 
  cscope kill -1
  cscope add GTAGS
endfunction

Thanks to Christian Brabandt for mentioning the -bar in the comments.

  • 2
    Shouldn't command -bar just work? – Christian Brabandt Oct 9 '15 at 7:11
  • Ah, yes, you are right. – Karl Yngve Lervåg Oct 9 '15 at 9:08
  • @ChristianBrabandt Your suggestion (the one with a -bar option) almost worked. For some reason it doesn't execute cscope add GTAGS. Am I missing something? – flashburn Oct 9 '15 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.