How can I include the contents of a register when recording a macro?
If I use Ctrl+R x I get a "pointer" to register
x, i.e., my macro will contain
^Rx instead of the register contents.
Often I need to record a macro which involves a substitution using a complex regex:
- create the regex with the aid of incremental search (
'incsearch'), and using highlight search results (
'hlsearch') to ensure that I'm matching the correct text
- create the substitution command with
s/<c-r>//<replacement>, so I end up with
- start recording a macro, do some stuff, repeat the substitution with :upENTER (or @:or :Ctrl+r:ENTER), add the end steps and stop recording the macro.
The problem with this approach is that the macro stops working as soon as I use another ex command.
I could copy the
: to another register and use it on the macro, but then it is necessary to keep avoiding to overwrite that register.
Currently I'm copying the substitution command on a split window an re-typing it, but certainly there must be a less cumbersome solution.