Handy: emacs prefix keyΒΆ

Tags: emacs, python

Despite emacs’ huge amount of key bindings, some actions you do regularly are bound to be not bound to a key binding. For instance sort-lines, so I regularly have to do alt-x sort-lines.

On a newsgroup someone mentioned he used prefix keys for some custom quick bindings. He send me his config example (thanks, Rohan!) and I modified it for my own usecase.

As prefix key I use f5, which I don’t use otherwise in emacs. It was the key in Rohan’s file and I just kept it. (f1-f4 is used for virtual desktop switching, so f5 was fine).

Here’s the code with the four bindings I added till now:

(define-prefix-command 'reinout-bindings-keymap)
(define-key reinout-bindings-keymap (vector ?u) 'org-mobile-push)
(define-key reinout-bindings-keymap (vector ?d) 'org-mobile-pull)
(define-key reinout-bindings-keymap (vector ?s) 'sort-lines)
(define-key reinout-bindings-keymap (vector ?f) 'auto-fill-mode)
(global-set-key [(f5)] 'reinout-bindings-keymap)

So if I select a couple of lines and press f5 s, the lines are sorted. Works like a charm. Better than alt-x sort-lines!

blog comments powered by Disqus
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):