How do I use the expression register in a mapping to insert dynamic values?
:nnoremap <leader>d "=strftime('%Y-%m-%d')<CR>p
The expression register (=) evaluates Vimscript expressions and uses the result as register content.
:nnoremap <leader>d "=strftime('%Y-%m-%d')<CR>p
The expression register (=) evaluates Vimscript expressions and uses the result as register content.
<C-r>=2+2<CR>
The expression register (=) in insert mode lets you evaluate any Vimscript expression and insert the result inline.
<C-r>=expand('%:t')<CR>
In insert mode, = opens the expression register.
<C-r>=42*7<CR>
In insert mode, press = to access the expression register, type a math expression like 42*7, and press Enter to insert the result (294).
:let i=1\nqao<C-r>=i\n<Esc>:let i+=1\nq
Use a counter variable with the expression register inside a macro.
:let i=1 then use <C-r>=i<CR> in macro
By combining a Vimscript variable with the expression register inside a macro, you can create a counter that increments on each replay.
<C-r>=expression<CR>
The expression register ("=) evaluates Vimscript expressions and returns the result.
registers #registers #insert-mode #expression #calculator #vimscript