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 registerNjumps back to the previous match, effectively returning to the original occurrencegUstarts the uppercase operatorgnsupplies 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
gUforgu,d, oryto apply different operators to matches - After priming search once, you can repeatedly use operator +
gnflows for targeted batch edits