GNU Emacs
Emacs
Dashboard

17.7 Stepwise Editing a Keyboard Macro

You can interactively replay and edit the last keyboard macro, one command at a time, by typing C-x C-k SPC ( kmacro-step-edit-macro). Unless you quit the macro using q or C-g, the edited macro replaces the last macro on the macro ring.

This macro editing feature shows the last macro in the minibuffer together with the first (or next) command to be executed, and prompts you for an action. You can enter ? to get a summary of your options. These actions are available:

  • SPC and y execute the current command, and advance to the next command in the keyboard macro.

  • n, d, and DEL skip and delete the current command.

  • f skips the current command in this execution of the keyboard macro, but doesn’t delete it from the macro.

  • TAB executes the current command, as well as all similar commands immediately following the current command; for example, TAB may be used to insert a sequence of characters (corresponding to a sequence of self-insert-command commands).

  • c continues execution (without further editing) until the end of the keyboard macro. If execution terminates normally, the edited macro replaces the original keyboard macro.

  • C-k skips and deletes the rest of the keyboard macro, terminates step-editing, and replaces the original keyboard macro with the edited macro.

  • q and C-g cancels the step-editing of the keyboard macro; discarding any changes made to the keyboard macro.

  • i key… C-j reads and executes a series of key sequences (not including the final C-j), and inserts them before the current command in the keyboard macro, without advancing over the current command.

  • I key… reads one key sequence, executes it, and inserts it before the current command in the keyboard macro, without advancing over the current command.

  • r key… C-j reads and executes a series of key sequences (not including the final C-j), and replaces the current command in the keyboard macro with them, advancing over the inserted key sequences.

  • R key… reads one key sequence, executes it, and replaces the current command in the keyboard macro with that key sequence, advancing over the inserted key sequence.

  • a key… C-j executes the current command, then reads and executes a series of key sequences (not including the final C-j), and inserts them after the current command in the keyboard macro; it then advances over the current command and the inserted key sequences.

  • A key… C-j executes the rest of the commands in the keyboard macro, then reads and executes a series of key sequences (not including the final C-j), and appends them at the end of the keyboard macro; it then terminates the step-editing and replaces the original keyboard macro with the edited macro.