Updated 2022.10.02

Apply macro in Emacs:

Emacs

How to use macros Emacs ways:

Find the reference from reddit

Vim/Doom

How to use macros Vim ways:

To save in init.el:

(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.

macro  doom  vim 
comments powered by Disqus