Install Theme

Your web-browser is very outdated, and as such, this website may not display properly. Please consider upgrading to a modern, faster and more secure browser. Click here to do so.

Glenn Stovall

Developer, Musician, Freelance Web Developer, and all around nice guy.

Facebook  |  Twitter  |  LinkedIn  |  Forrst  |  GitHub  |  StackExchange
Aug 10 '11

Emacs Protip: permanently save a keyboard macro

Keyboard macros can be crazy helpful in emacs, and allow you to automate repetitive processes you come across when coding. if you have a sequence of keystrokes you use day-to-day, here is how to convert them to a function and bind it to a key:

  • C-x ( to start your macro
  • type the keyboard strokes you want to save
  • C-x ) to end the macro
  • C-x C-k n to call kmacro-name-last-macro and assign a name to your macro
  • open your .emacs file
  • M-x insert-kbd-macro to output the lisp code of your new macro
  • then add (global-set-key <key> '<macro_name>) to bind it to a key. C-x C-k 0-9/a-z are reserved for personal key bindings. you can also use the f1 - f12 keys

and your done! now you have compressed several keystrokes into just one, and it’ll also be there when you need it.

5 notes Tags: programming emacs

  1. glennstovall posted this