Emacs: Keyboard Macro Commands

By Xah Lee. Date: . Last updated: .

Here's a list of all Keyboard Macro commands.


kmacro-start-macroCtrl+x (】 【C-x C-k s】, 【C-x C-k C-s】
start record.
  • (It relies on the primitive function start-kbd-macro)
  • defining-kbd-macro is an alias of start-kbd-macro.
kmacro-end-macroCtrl+x )
end record.
(It relies on the primitive function end-kbd-macro)


call the last keyboard macro.
apply last last keyboard macro to each line in text selection. TIP: to make this useful, you should create a macro that start at beginning of line, and do not move to next line.
kmacro-end-call-mouse 【S-<mouse-3>】
Move point to the position clicked with the mouse and call last kbd macro
Call the keyboard MACRO that you defined with kmacro-start-macro
End kbd macro if currently being defined; else call last kbd macro
kmacro-end-or-call-macro-repeat 【C-x C-k C-k】
As kmacro-end-or-call-macro but allow repeat without repeating prefix
kmacro-end-and-call-macroCtrl+x e
call the last keyboard macro. (stop it if still recording)


kmacro-name-last-macro 【C-x C-k n】
Assign a name to the last keyboard macro defined. (name-last-kbd-macro is an alias.)
Insert in buffer the definition of kbd macro MACRONAME, as Lisp code.
kmacro-to-register 【C-x C-k x】
Store the last keyboard macro in register. [see Emacs: Copy to Register] Call it by calling jump-to-register
kmacro-bind-to-key 【C-x C-k b】
When not defining or executing a macro, offer to bind last macro to a key


edit-kbd-macro 【C-x C-k e】
Edit a keyboard macro.
Edit the most recently defined keyboard macro.
Edit a keyboard macro which has been given a name by name-last-kbd-macro.
kmacro-edit-lossage 【C-x C-k l】
Edit most recent 300 keystrokes as a keyboard macro
kmacro-edit-macro 【C-x C-k RET】
As edit last keyboard macro, but without kmacro-repeat property
kmacro-edit-macro-repeat 【C-x C-k C-e】
Edit last keyboard macro
kmacro-step-edit-macro 【C-x C-k SPC】
Step edit and execute last keyboard macro


kmacro-add-counter 【C-x C-k C-a】
Add the value of numeric prefix arg (prompt if missing) to kmacro-counter
kmacro-insert-counter 【C-x C-k TAB】
Insert current value of kmacro-counter, then increment it by ARG
kmacro-set-counter 【C-x C-k C-c】
Set the value of kmacro-counter to ARG, or prompt for value if no argument
kmacro-set-format 【C-x C-k C-f】
Set the format of kmacro-counter to FORMAT
Record subsequent keyboard input, defining a keyboard macro


Display the last keyboard macro
kmacro-view-macro-repeat 【C-x C-k C-v】
Display the last keyboard macro
Display the second macro in the keyboard macro ring


kbd-macro-query 【C-x C-k q】, 【C-x q】
Query user during kbd macro execution.
Read the region as a keyboard macro definition.
Execute second keyboard macro in macro ring
kmacro-call-ring-2nd-repeat 【C-x C-k C-l】
Execute second keyboard macro in macro ring
kmacro-cycle-ring-next 【C-x C-k C-n】
Move to next keyboard macro in keyboard macro ring
kmacro-cycle-ring-previous 【C-x C-k C-p】
Move to previous keyboard macro in keyboard macro ring
kmacro-delete-ring-head 【C-x C-k C-d】
Delete current macro from keyboard macro ring
kmacro-swap-ring 【C-x C-k C-t】
Swap first two elements on keyboard macro ring

Emacs Keyboard Macro