Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Vim, if I want do a search that matches "planA" or "planB", I know that I can do this:


This works because the regex allows for either A or B as its set of characters.

But how can I specify one of two complete strings? For example, "planetAwesome" or "planetTerrible"?

This will match both of these, along with "planetAnythingHereAsLongAsItsJustLetters":


How can I match only strings that match "planetAwesome" or "planetTerrible" exactly?

share|improve this question
Actually, the brackets create a character class. plan[ABC] matches planA, planB, and planC equally well. – Christopher Bottoms Feb 23 '11 at 22:47
@molsecules - right, thanks. I updated the question. – Nathan Long Feb 23 '11 at 22:53
up vote 19 down vote accepted

To see the relevant documentation, issue :help /, and scroll down to the section “The definition of a pattern”.

share|improve this answer
Ah! I wasn't escaping the parentheses when I tried this. Interesting - I thought I only had to escape literal characters. – Nathan Long Feb 23 '11 at 23:39
@Nathan: Various regex engines have different rules about which characters must be escaped to make them special vs. must be escaped to make them literal (e.g. POSIX BRE vs. ERE). You can tweak the escaping requirements in Vim on a per-pattern basis by including one of the special escapes: \m, \M, \v, or \V. There is also the 'magic' option, but it is usually best to leave it alone, since it has global effect (unless overridden by one of the above flags). – Chris Johnsen Feb 24 '11 at 5:51

To add to Gilles' answer, you might want to add a few things in there:


\< marks the beginning of a 'word' (essentially alphanumerics)
\> marks the end of a 'word' (essentially alphanumerics)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .