How do I uppercase a word and then jump back to my exact original cursor position?
Answer
mzgUiw`z
Explanation
When you run an operator like gUiw, Vim can leave your cursor in a slightly different place than where you started. That is usually fine, but during dense refactors it breaks rhythm if you need to preserve your exact editing anchor. mzgUiwz` solves this by combining a temporary mark with the operator.
How it works
mzdrops markzat your exact current cursor locationgUiwapplies the uppercase operator to the inner word under the cursor`zjumps back to markzwith exact column precision
The key idea is not just uppercasing text, but building a repeatable pattern: mark first, perform the edit, restore position. That pattern is useful for many disruptive motions and operators, especially when you are making targeted changes across long lines and do not want to lose place.
Example
Before:
alpha beta gamma
Run:
mzgUiw`z
After:
ALPHA beta gamma
Tips
- This pattern works with other operators too, like
guiworciwworkflows - Prefer a rarely used temporary mark letter (such as
z) to avoid clobbering deliberate marks