Note: I'm assuming you're using the a
register for the entirety of this answer, but you can use any register
Note2: <1b>
is Esc; you can insert this with Ctrl+v and then Esc. It may also show up as ^[
(depending on the display
setting).
It's not a mapping; so it makes sense that :map
doesn't work. It's recorded in a register, and you can see & edit it like any register.
All that q does is "clear this register, and append any keystroke to it", and all that @ does is "evaluate a register as commands".
There is nothing "different" about a macro, you can invoke any register as a macro.
To view just use:
:echo @a
Just like any register.
You can also use :registers
to view all registers.
To edit you can do several things:
The simplest way you be to just assign to @a
, like so:
:let @a='iasd<1b>'
This will start insert mode (i
), insert asd
, and Escape back to normal mode.
This isn't very useful for extensive editing; you could use functions (ie. substitute()
), or maybe appending something (:let @a=@a . 'more'
), but changing something in the middle isn't that easy.
I've found that the best way for this, is to start a new buffer with :split
or :tabnew
and edit the register by inserting it there, editing it, and then copying it back.
You can use "ap which will insert the text in the buffer (where a
is your register):
iThis is A<1b>
Now I can just change the line to maybe:
iThis is an edited macro<1b>
Then I do ^v$"ay to yank (copy) this line to the a
register:
- ^ for start of line
- v for visual mode
- $ for end of line
- "ay yank the selection to register
a
If you wish, you can do this without using visual mode with ^"ay$.
You can now use @a, as if this is what you originally recorded.
You can also just use yy, and then @", which is a bit faster. This will also copy the trailing newline, though, and may cause side-effects... Another way to make this faster is to use a macro :-)