Is there any way I can concatenate a command after :terminal?

For example :terminal | <some_other_vim_command> will pass | <some_other_vim_command> to the terminal that just opened, but how can I prevent that from happening?

  • 2
    use :exe ":terminal" | another_vim_command Apr 23, 2020 at 11:28
  • Thanks, that seems to work!
    – msh
    Apr 23, 2020 at 11:32
  • 1
    @ChristianBrabandt I've been looking for a duplicate but can't find one... We do have some questions on :command missing -bar but we don't seem to have one on needing :exe for bar. Also, Vim help :| has a list of commands needing :exe but :term is not on that list and probably should be... If you'd like to take care of these that would be awesome, otherwise I'll take a closer look at them tomorrow. Cheers!
    – filbranden
    Apr 23, 2020 at 12:09
  • 2
    Yeah, looks like this is missing from Vims :h :bar. Will post a doc patch later. Apr 23, 2020 at 13:49

1 Answer 1


Not all Ex commands allow | to be used as a command separator, some Ex commands want to take | as an argument.

The common workaround is to use :execute to wrap those commands that do not allow | as a command separator.

See :help :bar or :help :| for more details and a list of commands that take | as an argument:

These commands see the '|' as their argument, and can therefore not be followed by another Vim command:

  • :argdo
  • :autocmd
  • ...
  • :normal
  • ...
  • :windo
  • :write !
  • :[range]!

Most Ex commands (such as :!) that take a shell command as an argument will not allow | as a command separator, since shell commands typically use | as a pipe between shell commands, so they'll pass the | literally to the shell.

Note that :terminal is not on that list (as of Vim 8.2.598) but that's just an omission in the documentation and @ChristianBrabandt offered to push a documentation patch to fix that in Vim.

The documentation in :help :| also mentions:

To be able to use another command anyway, use the :execute command.

Example (append the output of "ls" and jump to the first line):

:execute 'r !ls' | '[

And :help :execute also mentions that type of usage:

:execute can be used to append a command to commands that don't accept a |.


:execute '!ls' | echo "theend"

In your particular case, you can use:

:exe "terminal" | <some_other_vim_command>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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