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

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
  • p pastes 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>p evaluates register a as an expression
  • Useful for math, string operations, and dynamic content
  • "=system('command')<CR>p inserts shell command output

Next

How do you yank a single word into a named register?