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

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

  • mz drops mark z at your exact current cursor location
  • gUiw applies the uppercase operator to the inner word under the cursor
  • `z jumps back to mark z with 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 guiw or ciw workflows
  • Prefer a rarely used temporary mark letter (such as z) to avoid clobbering deliberate marks

Next

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