Using bar in external grep

From Vim Tips Wiki

Jump to: navigation, search
Tip 875 Printable Monobook Previous Next

created February 15, 2005 · complexity basic · author David S · version 5.7


It took me a while to notice this at :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 '\'.

When using bar in grep from a shell prompt you would use something like:

grep -i "main\(menu\|tool\)" *
  or
grep -iE "main(menu|tool)" *

However, you must remember to add an extra escape to the '|' character in your regex when using grep from Vim, like so:

grep -i "main\(menu\\|tool\)" *
  or
grep -iE "main(menu\|tool)" *

[edit] Comments

Personal tools