Search code examples
vimvim-fugitive

Vimrc: combine commands with fugitive


I'm trying to combine

:w
:Gcommit -a -m "update"
:Gpush

to a new Command like :W – I've tried

:command! W w | Gcommit -a -m "update" | Gpush

But it doesn't work because he treats Gpush as a shell-command instead of a vim-command.


Solution

  • :command! W w | execute "Gcommit -a -m 'update'" | Gpush
    

    Gcommit has not been given -bar argument that would allow it to terminate at the bar (and prohibit it from taking the bar as an argument). Thus, use execute to isolate the command, as described in :help :|. See also :help :command-bar.