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
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.)