I like to use the :@
command to execute a register containing Vimscript.
It's quite convenient to test a snippet that will go into vimrc or into a *.vim
script. It has one main limitation, which is that it doesn't support line continuations with backslash, so beware of that. You can't use it to define s:
functions either.
You still end up typing four characters (:@"
and the "Return" key), so I often add a mapping to run the current line or run the visual block:
xnoremap <buffer> <F5> y:@"<CR>
nnoremap <buffer> <F5> yy:@"<CR>
Note I made these <buffer>
mappings, they make sense in Vimscript files, so you might want to add those to a ~/.vim/ftplugin/vim.vim
file.
Also note that the normal-mode mapping will work with a count, so 12<F5>
will run the commands in the 12 lines starting with the current one as Ex commands.
(It also overwrites the default register. You can probably rework them to take an optional register if you like, or save/restore registers if you want it not to leave behind any trace.)
<Ctrl-r>"
should be enough.nnoremap <f1> :<C-r>"
(where you can replace<f1>
by any key you prefer to use)? Thectrl+o
probably came from:h c_CTRL-R_CTRL-O
EDIT Or you can use Fill's solution :)