Vim: The useful Ctrl-R
I often use Ctrl-R % to insert the current file name, for example, to make a
copy of the current file:
:saveas [Ctrl-R %] # turns into :saveas /Users/my/blog/posts/2026-17-10-vim-ctrl-r-is-good.org
Ctrl-R can be used in insert mode or on the command line to paste:
Ctrl-R a-z- named registerCtrl-R "- default registerCtrl-R %- current file nameCtrl-R #- alternate file nameCtrl-R * / +- clipboard contentsCtrl-R /- last searchCtrl-R :- last command lineCtrl-R .- last inserted textCtrl-R -- last small deleteCtrl-R =- evaluate expression (for example, in insert mode,Ctrl-R =, then2+2and Enter)
The % and # also work as current file and alternate file aliases on the command line.
For example, :!ls % will show the current file name.
A more useful example: :!git add % stages the current file with git.
Only in command-line mode:
Ctrl-R Ctrl-W- word under the cursorCtrl-R Ctrl-A- WORD under the cursorCtrl-R Ctrl-L- line under the cursorCtrl-R Ctrl-F- file name under the cursorCtrl-R Ctrl-P- file name under the cursor, expanded with'path'(as ingf)Ctrl-\ e {expr}- evaluate the expression and replace the command line with the result
See :help i_CTRL-R and :help c_CTRL-R.