For example, substitute
: with register 0's content.
What's the correct command for
N.B. In all the below, I presume that your question is only about the method of accessing the register's contents from an ex command, and that the rest of your
:substitute command (which replaces only the first match on the current line) does what you require. If you actually want to replace globally, you will need to use a
% range and the
Interactively in Command Line Mode
If this is being done interactively, you can do so by inserting the contents of the register into the command using Ctrl-R:
Type the first part of your command,
Then type Ctrl-R0 to insert the contents of the yank register
"0 into the command line.
Note that you may need to then edit the command line slightly before pressing Return to run the substitution. e.g. if the register contained a string that included a forward slash
If this is in a script, then you can use the
@0 notation or the
getreg() function to access register contents. You can also then perform escaping automatically.
execute 's/:/' . escape(getreg('0'), '/')
Update: In a Macro
If you want to do this in a macro recorded from keystrokes, the first method works fine: Ctrl-R is recorded just like other keystrokes.
If you're instead creating a macro by assigning a string value to a register, you can use something like the below:
:let @q = ":s/:/\<C-R>0\<CR>"
I'm using the
:let command above for simplicity, but the
setreg() function is more robust.
Besides @Rich's solution of using a substitution,
:s, uou can use the
<c-r> to do this as well.
Now you can simply spam repeat,
. to do the next substitution.
However if spamming the dot command is not desirable, then you can make a macro to do it for you.
:let @q = '.@q'
Now you can simply run the macro from the
"q register via
@q which will repeat the
. command until it runs out of matches.