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

How do I uppercase only the current search match using gn as a motion?

Answer

*NgUgn

Explanation

gn is often treated as a visual selection command, but it is more powerful when used as a motion target for operators. *NgUgn turns that into a compact workflow: prime the search from the word under cursor, return to the current occurrence, then uppercase exactly that match.

How it works

  • * searches forward for the word under cursor and sets the search register
  • N jumps back to the previous match, effectively returning to the original occurrence
  • gU starts the uppercase operator
  • gn supplies the motion as the next search match span

Because gn defines a match-aware text region, you get precision without manual text objects or character counts. This pattern is especially useful when you want to apply operators to search hits one occurrence at a time.

Example

Before:

token token token

Run with cursor on the first token:

*NgUgn

After:

TOKEN token token

Tips

  • Swap gU for gu, d, or y to apply different operators to matches
  • After priming search once, you can repeatedly use operator + gn flows for targeted batch edits

Next

How do I move the current split into a new tab and immediately jump back to the previous tab?