Vim has a few more special operators:
Symbol |
Meaning |
| |
alternation |
() |
grouping |
The alternation operator is used to signify or. For example, carrot|parrot matches both carrot and parrot.
Grouping is used to put multiple characters in a group, which can serve two purposes. Firstly, you can combine operators with each other. For example, (c|p)arrot is a nicer way to match both carrot and parrot.
Grouping can also be used to later refer to each section in parentheses. For example, if you wanted to turn the string cat hunting mice into mice hunting cat, you could use the following :substitute command:
:s/(cat) hunting (mice)/2 hunting 1
This becomes relevant during refactoring; for example, when reordering arguments—but more on that later.