Emacs Keybindings Everywhere!

Full Emacs Keybindings on your Mac. It is possible!

Last updated: 17 Jan 2021

Are you accustomed to Emacs keybindings? You’ll find that your beloved Mac doesn’t give you complete Emacs keybindings.

Because Emacs keybindings on your Mac isn’t complete, it can be frustrating to even try using Emacs keybindings on it. Some keybindings work, some don’t!

The Shortfall

To see this inconvenience and frustration in action, open Safari (I’m using Safari 14.0.2 on macOS 11.1). In Safari’s address bar (press Cmd-l, that’s lower caps for ‘L’), which doubles as a search bar, type a simple sentence like “this is a sentence”. Moving forward/backward by 1 character works as per Emacs: Ctrl-f and Ctrl-b, respectively.

If you’re an Emacs keybindings user, you’ll likely have mapped your Caps Lock key to mean “Control key”. Just FYI. Official instructions to do that at here.

Now, try moving forward/backward by 1 word at a time. On Emacs, the keybinding is Meta-f and Meta-b, respectively (where Meta is your alt/option key). Doesn’t work? The official Mac keybinding for that is Ctrl-Meta-f and Ctrl-Meta-b instead!

The Complete Mac Keybinding List

The first thing to do is to figure out the keybindings that come with your Mac. They’re specified in a StandardKeyBinding.dict file:

We’re looking for entries moveWordForward: and moveWordBackward:.

(In case you’re not familiar with using the program less, here’s a very nice guide for it.)

The Override

The next thing to do is to create some overrides. Create an empty file ~/Library/KeyBindings/DefaultKeyBinding.dict and paste this into it:

The @ sign stands for Cmd key. The official documentation is outdated/incomplete, as usual, so the full list of modifier keys are:

  • @ : Cmd
  • ~ : Meta (or alt/option)
  • ^ : Ctrl
  • $ : Shift
  • # : Numeric keypad

Did I miss out anything? Let me know if you need me to fill in more details! (I wrote this quick article because I found myself forgetting the lessons here and re-researching all these.)

Jon writes technology tutorials, fantasy (a dream), linguistics (phonology, etymologies, Chinese), gaming (in-depth playthrough-based game reviews).