Keyboard customization for Emacs

In order to use Emacs effectively you have to customize your keyboard bindings. You really do have to do this one way or another. For a long time I tried to use the “standard” emacs bindings but eventually I realized you really can’t be productive that way.

I’ve been using Macbooks for several years now for my primary code editing device. Here’s how I have customized my keyboard.

First know that I use both emacs and vi. (I will always call it vi (pronounced “v” “i” two syllables). I used vi many years before vim came about and so even though I use vim I will always call it vi), so I need the Escape key for both. I use emacs as my primary code editor and dev IDE. But I’ll use vi when I just need to do quick edits, especially over ssh.

On a Macbook the escape key is kinda far away on the upper left corner. In fact on the new Macbooks they’ve removed it completely. Ridiculous.

Swap Control and Caps Lock keys. The built in Keyboard settings in the System Preferences, under Modifier Keys. Here I swap Control and Caps Lock. This puts the much needed Control Key within easy reach of left pinky. This is a must for emacs users and as you’ll see a life saver for vi users too.

Karabiner: I use for several keyboard customizations:

  • Caps Lock overloaded With Karabiner I use the Caps Lock key for a 2nd function: if pressed-and-released then ESCAPE. So when I press and release the Caps Lock key it issues an Escape char. So this replaces the need for the physical Escape key! Note that I use this both for vi and emacs. In vi Escape is used to exit insert mode. And in emacs Escape can be used as the Modifier key. Winning.
  • C-, and C-. for word left/right I find emacs’ out-of-box bindings for word left & right to be cumbersome so in Karabiner I bind C-, and C-. to C-B and C-F respectively. I find the , and . easier to use. The reason I do this in Karabiner instead of just mapping in Emacs is so that I have them available in the Terminal bash shell when editing commands, as well as in emacs.
  • Return+ to Option_L Also in Karabiner, when I hit Return and release, it’s just a Return. But if I hold Return down then it acts like the Option_Left key (Alt) which is the Meta key in Emacs. One disadvantage with this is that I lose the key repeat for Return key. But C-j suffices for that. I’ve found tho that I don’t use Return+ as Meta key. Rather I just use the CapsLock+release described above.

Karabiner has myriad ways to customize the keyboard. One thing for mac users, apparently Sierra totally changed the keyboard api, or something, so much that Karabiner won’t work at all. If you go read the info the guy has started working on the Sierra version of Karabiner but it may not be near as good. So, when I upgraded to Sierra last year and discovered this, I immediately went back to Capitan and will stay hear till I get Karabiner-like ability..

These days I’m a single computer person. I use nothing other than my laptop (** which happens to be a Macbook see below) so the above works for me. In the past it wouldn’t work cause I used to use multiple computers throughout a day. But for now this works.

(** which happens to be a Macbook, I’m not a fan boy or anything I just like unix and apple makes a decent laptop. But, since they’ve seen fit to produce this abomination of a laptop with no Escape key and the “touchbar” I may never get another macbook. May have to try a System76 or something made for Linux).

I guess that’s it.