vimtricks.wiki Concise Vim tricks, one at a time.

How do I search for a whole word only, excluding partial matches?

Answer

/\<word\>

Explanation

The \< and \> atoms create word boundaries in a search pattern, matching only complete words and not substrings within larger words.

How it works

  • \< matches the start of a word
  • \> matches the end of a word
  • /\<the\> matches the but not there or other

Example

the theory of the other theme

Searching /\<the\> matches only the two standalone the words, not theory, other, or theme.

Tips

  • * and # automatically add word boundaries
  • Boundaries work in :substitute too: :%s/\<old\>/new/g
  • \< matches at a transition from non-word to word character
  • Word characters are letters, digits, and underscores

Next

How do you yank a single word into a named register?