12 Emacs Keybindings Worth Learning

After spending a bit of time learning Emacs, I’ve found it has a widespread compatibility with a lot of the basic movement and editing commands. Spending a bit of time learning these commands can make you more effective in a variety of places, even if you don’t use Emacs as your preferred editor.

Useful Emacs Keybindings

The most basic bindings that I’ll cover here are shortcuts that let you move your cursor around and delete text. On macOS, it’s worth noting that the Option key is the Meta key. On Windows, this is usually the Alt key.

Moving and deleting by words

FunctionKeyboard shortcutAlternative in macOS
Move forward one characterControl-f
Move backward one characterControl-b
Delete forward from the cursorControl-d
Move forward one wordMeta-fControl-Option-f
Move backward one wordMeta-bControl-Option-b
Delete the last wordMeta-Delete
Delete the next word (forward)Meta-d

Moving and deleting by lines

FunctionKeyboard shortcutAlternative in macOS
Move up one lineControl-p
Move down one lineControl-n
Move to the beginning of the lineControl-a
Move to the end of the lineControl-e
Delete to the end of the lineControl-k

Where Do They Work?

It’s quite likely that a lot of the software you interact with as a developer has support for these commands hidden away. For example, all of these should work out-of-the box on your shell and most programs, especially if they use the GNU readline library.

As it turns out, many of the default Emacs commands are also implemented by the text editing system built into macOS. This makes them available pretty much anywhere you’re entering text, even in your browser’s URL bar or when you’re composing an email.

Given Emacs’ long and influential history, I’ve found that you can just try to use them somewhere, and you will often find success.

Some Example Use Cases

I often find myself using these shortcuts for scenarios such as:

  • Quickly deleting the last word I (mis)typed using M-del, before retyping it
  • Jumping back a few words on the command line so I can change or insert an argument to the program before I invoke it
  • Abandoning and deleting the line I’ve been typing with C-a C-k

Why Not VI Bindings?

I used to be one of those people who enabled VI bindings in my shell. For short editing tasks, I found the friction to be too much. It’s a lot easier to press M-b a couple times and resume typing, without the mental overhead of modality. Dealing with modality at the shell can often be quite jarring.

Beyond this, Emacs bindings are available in a lot more places.

Next Steps

Did you know there’s also a command for transposing words? It’s M-t. This one can be handy for switching arguments around at the command line. There are a lot more Emacs commands that are commonly implemented. To learn more, I suggest reading the Emacs or the GNU Readline documentation.

If you’ve ever found yourself using the arrow keys to navigate text at the command line slowly, character by character, I hope you’ll have found this post useful.