emacs - macros

Table of Contents
    - [Macros](#macros)
    - [How to record a macro in emacs?](#how-to-record-a-macro-in-emacs)
    - [How to execute a macro?](#how-to-execute-a-macro)

Macros

https://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macros.html

https://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macros.html

How to record a macro in emacs?

F3 - Start defining a keyboard macro (kmacro-start-macro-or-insert-counter).

F4 - If a keyboard macro is being defined, end the definition; otherwise, execute the most recent keyboard macro (kmacro-end-or-call-macro).

How to execute a macro?

Just keep hitting F4

How to run a macro on all lines in a file or on all selected lines?

You can use the “apply-macro-to-region-lines” function to apply the last defined keyboard macro to all lines in a region. So, the steps you follow are:

  1. Define your keyboard macro
  2. Select the whole buffer with the mark-whole-buffer command (by default, it’s bound to C-x h). Alternatively, if you just want to change a certain number of lines, just select the lines you want changed.
  3. Run the apply-macro-to-region-lines function (by default, it’s bound to C-x C-k r).

Links to this note