Short and Sweet with Emacs in Xcode

Did you know that a subset of Emacs hotkeys is supported in Xcode? In fact, as far as I know, these hotkeys can be used throughout macOS making you, just that more productive.

Hotkey Basics

First, if you are new to macOS and you try to look up the hotkey for something and you see some symbols you don’t recognize, let’s clear up the two most confusing ones.

  • the funny carrot hat looking thing is the control key
  • the ramp is the option or alt key

I try to remember the key by thinking that the icon starts at one point from the left, and then splits to give you two choices on the right or optional choices.

Replacement for Arrow Keys

You can use⌃ F and ⌃ B to move forward and back instead of using your or keys on your keyboard, and ⌃ P and ⌃ N to go or . Now, do I actually use these? No. Even though I use the crazy Kinesis Advantage 2 keyboard where the arrow keys are placed in a very awkward spot, I still use the single arrow keys over two key presses for the same action. But depending on if you are a heavy Emacs user or maybe on your keyboard, it’s easier to use control and a letter than the arrow keys, now you know they exist.

Start and End of Line

These I actually do use all the time. You can use ⌃ A to go to the beginning of a line and ⌃ E to go to the end of the line. Yes, you can do this same action with ⌘ ← or ⌘ → , but sometimes ⌃ A and ⌃ E are easier for me, especially if I’m using a Terminal app and already in the mindset of using control for other hotkeys.

Delete

You can use ⌃ K and ⌃ Y to kill and yank characters. Most of us non-Emacs users know these as cut and paste. What sets these apart from the typical cut and paste is killing a complete line. For example, if you don’t highlight any text, ⌘ X does nothing. ⌃ K on the other hand, takes where your cursor is and kills to the end of the line. You can then yank or paste it somewhere else with ⌃ Y .

Where I find myself using ⌃ K the most is with killing a complete line. If your cursor is in the middle of the line, in order to delete the complete line, you can use ⌘ → to go to the end of the line and then ⌘ Delete to delete the line backwards. Or you could use ⌘ ← to go to the beginning of a line, highlight the line with ⌘ ⇧ → and then hit Delete or Fnc Delete. Both of those solutions require the use of the arrow keys, and depending on where your arrow keys are located on your keyboard, that’s not always the most useful. So what I find is a bit easier, is to use the hotkey we learned in the last section,⌃ A , to go to the beginning of a line followed by ⌃ K to kill to the end of the line.

Instead of the traditional Delete key, you can use ⌃ H instead. This one might not be as useful than the singular Delete key, but what I do find useful is ⌃ D . ⌃ D is the same key combination as Fnc Delete to delete a key forward. So instead of using your pinky fingers to delete a key forward on the tiny Mac keyboard, try out ⌃ D and see if that’s more comfortable for you.

Conclusion

A subset of the Emacs hotkeys can be used in not only Xcode, but throughout macOS. Depending on how you like to work, some of these might be more efficient or more comfortable for you. If you want to learn more about hotkeys and Xcode, check out my course, Becoming an Xcode Power User on Pluralsight.