Updated 2022.10.02
Apply macro in Emacs:
Emacs
How to use macros Emacs ways:
C-x (
to start recording macroC-x )
to stop recording macroC-x e
to execute the last macro definedM-x name-last-kbd-macro
to name last defined macroM-x insert-kbd-macro
to save named macro (copy result to .emacs file)M-x macro_name
to run your macro
Find the reference from reddit
Vim/Doom
How to use macros Vim ways:
q a
letter to start recording a macroq
to stop recording@ a
letter to run the last recorded macro
To save in init.el
:
q a i foo ESC q
will save macro to insert foo ina
registerM-x name-last-kbd-macro RET mymacro RET
to name the macro- Open
init.el
file and runM-x insert-kbd-macro RET mymacro RET
which will dump your macro into afset
call as:
(fset 'mymacro [?i ?f ?o ?o escape])
To be able to use @ a
to run the macro instead of using M-x mymacro
then
you need to add to evil register
:
;; make sure this is done after evil-mode has been loaded
(evil-set-register ?a [?i ?f ?o ?o escape])
For reference please read it in StackOverflow
Repeating
To repeat or execute macro multiple times
Emacs
Emacs style with C-u <number> C-x e
where <number>
is the number of times to
repeat the macro. Else can use C-x e
then C-x z
to repeat previous command.
See more details in Wiki.
Vim/Doom
Use normal command to run macro multiple times:
To run macro saved in @a
through line 5 to 10
:5,10norm! @a
To run macro saved in @a
through line 5 to end of file
:5,$norm! @a
To run macro saved in @a
on all lines
:%norm! @a
For reference please read in StackOverflow
To repeat macro a
with a certain number of times eg. 5 times then :5@a
. To
repeat the last macro you can do @ @
or to repead 12 times then type 12@@
.
You can map it to another command eg. :map , @@
to map @@
to ,
for easy
typing.