Question

I am trying to combine two commands for Bundle plugin in vim. Because BundleUpdate pulls all plugins and installs them and it is slow. I have the following below. The first two works fine, but the third one does not. It stops after the BundleClean operation. How can I make vim to run second command?

command! -bang BI BundleInstall<bang>
command! -bang BC BundleClean<bang>
;not working below
command! -bang BU BundleClean<bang> | BundleInstall<bang>
Was it helpful?

Solution

You should use -bar as an argument to :command in addition to -bang, otherwise chaining commands and adding comments is not possible for user-defined commands.

You will have to use

command! -bar -bang BU BC<bang> | BI<bang>

in place of what you have currently because Bundle* commands do not have -bar argument.

There is another alternative: use execute:

command! -bang BU execute 'BundleClean<bang>' | execute 'BundleInstall<bang>'

. Beware of using execute '…<some-arg>', it is not going to work properly for some arguments’ values. It works fine for both possible expansions of <bang>.

OTHER TIPS

You cannot do BundleClean | BundleInstall.

Because BundleClean is a user-defined command, it is defined by Vundle plugin:

 com! -nargs=? -bang   BundleClean call vundle#installer#clean('!' == '<bang>')

Note that, there is no -bar in this command definition.

If you :h command-bar you will see:

-bar        The command can be followed by a "|" and another command.
        A "|" inside the command argument is not allowed then.
        Also checks for a " to start a comment.

that is, the BundleClean cannot be followed by another command by |.

You could however write a function, in the function you execute the two commands. And let your BU command call your function.

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