This is a pretty curious request since there is no "mode" for recording a macro. After digging through some docs I found the following in
You start by moving to the first character of the first line. Next
you execute the following commands:
qa Start recording a macro in register a.
^ Move to the beginning of the line.
i#include " Insert the string #include " at the beginning of
$ Move to the end of the line.
a" Append the character double quotation mark (") to the end
of the line.
j Go to the next line.
q Stop recording the macro.
The standout thing to me was the line about "Start recording a macro in register a"
Since each macro is going to be saved to a register by default I was hoping that we'd be able to see it in the
:reg list. It turns out it works like a charm!
In normal mode:
and inside of
:reg we see the entry!
With that knowledge you should be able to "spy" on the registers to confirm that a macro is being recorded (use a named register on every recording [map
q to always use the same register (or something like that )]
If you run into problems let me know and I'll try to help you out (since this functionality is new to me too :D)
To address the issue of a register being used during yank I'd recommend to look into a special type of register that you can use only for the
vimL you are writing (no yank would ever be engaged on the register (
Here's a bit of info from
:help registers on the available registers
There are ten types of registers: registers E354
The unnamed register ""
10 numbered registers "0 to "9
The small delete register "-
26 named registers "a to "z or "A to "Z
three read-only registers ":, "., "%
alternate buffer register "#
the expression register "=
The selection and drop registers "*, "+ and "~
The black hole register "_
Last search pattern register "/
Assuming that you have a register that you are going to use now the issue becomes "how do I know when recording has stopped?". To take care of this I'd take a look at the
CursorHold; the note in the help docs looks pretty promising (I'd try to figure out how I could differentiate normal cursorHold vs the idle/non-existant event that occurs when your register is being written to for the purposes of the macro)
When the user doesn't press a key for the time
specified with 'updatetime'. Not re-triggered
until the user has pressed a key (i.e. doesn't
fire every 'updatetime' ms if you leave Vim to
make some coffee. :) See |CursorHold-example|
for previewing tags.
This event is only triggered in Normal mode.
It is not triggered when waiting for a command
argument to be typed, or a movement after an
While recording the CursorHold event is not