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 eto execute the last macro definedM-x name-last-kbd-macroto name last defined macroM-x insert-kbd-macroto save named macro (copy result to .emacs file)M-x macro_nameto run your macro
Find the reference from reddit
Vim/Doom
How to use macros Vim ways:
q aletter to start recording a macroqto stop recording@ aletter to run the last recorded macro
To save in init.el:
q a i foo ESC qwill save macro to insert foo inaregisterM-x name-last-kbd-macro RET mymacro RETto name the macro- Open
init.elfile and runM-x insert-kbd-macro RET mymacro RETwhich will dump your macro into afsetcall 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.