How do I paste the unnamed register after transforming it to uppercase?
Answer
:put =toupper(@")
Explanation
Registers in Vim are not only for raw replay; you can treat them as string data and transform them at paste time. :put =toupper(@") reads the unnamed register (@"), converts its contents to uppercase with toupper(), and inserts the result below the current line. This is useful when you already yanked text and want a transformed variant without clobbering any register or editing the original snippet manually.
How it works
@"references the unnamed registertoupper(...)returns an uppercase copy of that string:put =exprevaluates an expression and inserts the resulting text as new line(s)
Because this pipeline is expression-based, you can swap in other transformations (tolower(), substitute(), concatenation) while keeping the same :put =... shape.
Example
- Yank a line:
yy(now in unnamed register) - Move elsewhere and run:
:put =toupper(@")
If the register held ReleaseCandidate, Vim inserts RELEASECANDIDATE below the cursor.
Tips
- Use
:put! =...to insert above the current line instead of below. - For partial normalization, chain functions:
:put =substitute(toupper(@"), '-', '_', 'g'). - This keeps your original yanked text untouched, which is safer than overwriting registers during one-off transformations.