How do I use the expression register for calculations?
Answer
"=2+3<CR>p
Explanation
The expression register = evaluates a Vimscript expression and stores the result. You can use it for inline calculations or dynamic text insertion.
How it works
"=enters the expression register prompt in normal mode- Type any Vimscript expression
- Press
<CR>to evaluate ppastes the result
Example
To insert the result of 42 * 7:
"=42*7<CR>p
Inserts 294 at the cursor.
Tips
- In insert mode,
<C-r>=opens the expression prompt directly - Any Vimscript function works:
"=strftime('%H:%M')<CR>p "=@a<CR>pevaluates registeraas an expression- Useful for math, string operations, and dynamic content
"=system('command')<CR>pinserts shell command output