Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a single key binding for a sequence of commands in Emacs

Tags:

emacs

emacs24

The Emacs manual only has an example to set a binding for a single command. How to do so for a sequence of commands. Specifically the following.

  • [M-down] to [C-u 1 C-v]
  • [M-up] to [C-u 1 M-v]

Which is practically single line scrolling.

like image 960
Ébe Isaac Avatar asked Apr 29 '15 09:04

Ébe Isaac


1 Answers

You can use keyboard macros for that task. The link pretty much explains how to do it, for completeness here's what to do:

  1. Hit C-x ( to start recording a keyboard macro.
  2. Do what the command is supposed to do (i.e. execute commands, hit keys, ...)
  3. Hit C-x ) to stop recording the keyboard macro.
  4. Execute M-x name-last-kbd-macro to name the last-defined keyboard macro (i.e. the one you just defined).
  5. Execute M-x insert-kbd-macro to insert the code of the last defined macro at point, copy it into your init file.
  6. Put (global-set-key (kbd "M-n") 'my-macro) into your init file (assuming you named the macro my-macro).
  7. Profit!
like image 124
elemakil Avatar answered Sep 24 '22 13:09

elemakil