Quick keybindings

So, you just executed a complex, wonderful emacs command using the minibuffer and you’re so excited that need to immediately write it down, lest you forget. As you may already know, you don’t need pen and paper for that. Emacs will do it for you: just press C-x ESC ESC (that is, repeat-complex-command) and you’ll see an Elisp form in your minibuffer that reproduces your last command (C-h w C-x ESC ESC for more details). Now C-a C-k and you got it in the kill-ring, ready to be yanked in one of your configuration files.

I don’t use this trick that much because over the years more and more emacs automatisms are recorded either in my nervous system or my config files. Except for one thing: defining keybindings. There’re a bunch of ways to define a keybinding in emacs, and i’m never sure what’s the right one when there’re special keys involved. The solution is to define the key interactively with M-x global-set-key. Once i’m done, i play C-x ESC ESC and presto: an elisp snippet to yank in my .emacs appears in the minibuffer.

Happy binding!

About these ads

3 Responses to “Quick keybindings”

  1. pp Says:

    Thanks for the interactive global-set-key trick,
    I finally found out how to bind M-space! (“\240″ !!)

  2. Top Posts « WordPress.com Says:

    [...] Quick keybindings So, you just executed a complex, wonderful emacs command using the minibuffer and you’re so excited that need to […] [...]

  3. clickonce Says:

    An easier way to figure out the key you need to specify for global/local-set-key is to use the kbd macro.

    C-h c M-space –> M-SPC runs the command just-one-space
    or
    C-h c C-F3 –> is undefined

    then simply use the key that it told you and wrap it with kbd.

    (global-set-key (kbd “M-SPC”) ‘my-func)
    (local-set-key (kbd “”) ‘another-func)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: