Vim provides handy commands to match words under (or near to) the cursor. You can choose to match whole or part of a longer word. If a match is found, the cursor will move to the next match in the chosen direction.

  • * searches the word nearest to the cursor in the forward direction (matches only the whole word)
    • Shift followed by left mouse click can also be used if mouse is enabled
  • g* searches the word nearest to the cursor in the forward direction (matches as part of another word as well)
    • for example, if you apply this command on the word the, you'll also get matches for them, lather, etc
  • # searches the word nearest to the cursor in the backward direction (matches only the whole word)
  • g# searches the word nearest to the cursor in the backward direction (matches as part of another word as well)

From :h word:

A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, <EOL>). This can be changed with the iskeyword option.

Sequence of non-blank characters will be used only at the end of the line. Otherwise, the above commands will use the next word found on that line which is made up of letters, digits and underscores.

info You can also provide a count prefix to these commands. For example, 2* will take you to the second match in the forward direction.

Video demo:


info See also my Vim Reference Guide and curated list of resources for Vim.