In answering a question just now, I mentioned using a normal mode key mapping that can be found at the Vim Tips Wiki. In the middle of explaining the key mapping, I realized that I had no idea what <Bar> meant. What does it mean?

I tried replacing it with a pipe |, with and without spaces before, around, and after it, but each one broke my .vimrc file with the following error message:

Error detected while processing /home/bottomsc/.vimrc:
line  173:
E488: Trailing characters: :nohl<CR>

It's the code for the pipe character: |. The pipe is used the way the semicolon is used in C-style languages, as a statement separator. You cannot use it directly in a mapping, since it would be seen as marking the end of the mapping. Hence, the code has to be used instead.

There are exceptions to this, such as autocmd definitions, where the bar delimits the actions of the autocmd, but not the definition itself.

From :help :bar:

'|' can be used to separate commands, so you can give multiple commands in one line. If you want to use '|' in an argument, precede it with '\'.

and from :help map_bar:

Since the '|' character is used to separate a map command from the next
command, you will have to do something special to include  a '|' in {rhs}.
There are three methods:
   use       works when                    example      ~
   <Bar>     '<' is not in 'cpoptions'     :map _l :!ls <Bar> more^M
   \|        'b' is not in 'cpoptions'     :map _l :!ls \| more^M
   ^V|       always, in Vim and Vi         :map _l :!ls ^V| more^M

If you type

:help <Bar>

you will read that

<Bar>           vertical bar            |       124     <Bar>

I'd like to add that in normal mode, the | command (which has to be substituted with <bar>, \| or ^V| while remapping it, as mentioned in other answers) allows you to go to a specific screen column in the current line.

For example, typing 5| will go to screen column 5, as in the image below:

enter image description here

That's what the | means by default in vim.

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.