I have used this script to be able to highlight results from test reports: https://vim.fandom.com/wiki/Highlight_multiple_words

When using it in Vim, it works fine when I type :Highlight 1 FAILED (For some reason the numpad-keys don't work).

Unfortunately, this is not session persistent, so what I was planning to do is create a chain of these commands and add them to my notepad where I store frequently used commands. In this case, I could use it every time I open a test-report.

So for example, I would use: :Highlight 1 FAILED | :Highlight 2 PASSED. Unfortunately this didn't work. I also tried escaping the pipe and removing the second colon. Strangely enough, when trying echo "a" | echo "b" it does work?

What am I doing wrong here? How do I chain these commands properly?

  • Note that even though the context is the same as this question, It is NOT a duplicate.
    – Opifex
    Apr 4, 2022 at 12:26
  • 3
    See :help command-bar
    – D. Ben Knoble
    Apr 4, 2022 at 14:48
  • @D.BenKnoble I must be missing something obvious? What am I supposed to see there? I see some explanation about how to use "bar" (which I guess is a strange way of describing the pipe symbol?), but isn't that precisely what I did with the echo's in my example?
    – Opifex
    Apr 4, 2022 at 17:24
  • Maybe it’s :help :command-bar; should be the explanation on adding the -bar attribute to user-commands to allow the chaining to work
    – D. Ben Knoble
    Apr 4, 2022 at 17:53

1 Answer 1


What exactly happens when using the | after a custom command (that is defined using :com (see in the help at :h :command-bar.

In short, if you know that your argument cannot contain the | character, you should add the -bar argument to your command definition, so that a user can always chain several commands using the :A | :B syntax. (This means the command :A was defined as followed :command -bar A ....)

In your specific case this doesn't seem to be the case. The usual work-around to that is to wrap the command into an :exe statement, which are then allowed to be chained by using the bar |. So you can use:

:exe ":Highlight 1 FAILED" | :exe ":Highlight 2 PASSED"
  • Thanks! The sample you gave worked indeed, so upvoted already! I'm trying to understand the rest of your answer though. You say something about not being allowed to use | in a command, but in the A-B example you do use one? What's the difference there? Also: where should I add this -bar argument? Simply behind the command? Like :command A | :command B -bar ? I've never seen this kind of syntax in Vim before. I've been exclusively using Vim for 2 years now, and I still feel like there's so much I don't understand yet :)
    – Opifex
    Apr 5, 2022 at 7:25
  • you need to add the -bar to the definition of the command. E.g. you need to define command A like this: :command -bar A :echo foobar and then you can use :A | echo "bar". Apr 5, 2022 at 8:54
  • Okay, thanks for the explanation. I it didn't work in this case (but you already pointed that out in your answer), but it's good to know for the future.
    – Opifex
    Apr 5, 2022 at 8:57

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.