Before you get going with Emacs on a Mac, there are a number of keyboard settings that you generally want to tweak to get the most fluid and comfortable experience. This post outlines the keyboard settings changes I’ve made that I find essential.
Note: this is targeted towards OSX users. Not all of this will apply to other systems.
Caps lock as control
This one is generally considered pretty universal. The most common location of `Control` on modern keyboards (in particular laptop keyboards), is not very accessible from an ergonomic perspective. This change restores the most desirable location for `Control`. On OSX, this is pretty easy to do. Just go to:
`System Preferences -> Keyboard -> Modifier Keys..`
You will get a window showing you the current mappings. Just change the `Caps Lock key` to `^ Control` in the pull down list.
One note if you tend to work with multiple keyboards (say an external keyboard hooked up to your laptop). Pay attention to the top-most pull-down menu. This will only appear if you have an external keyboard connected. So if you’re wondering why the setting change isn’t taking effect, it may be because you only toggled it on your internal keyboard, or vice-versa.
Rebinding Meta to Command key instead of alt
Not everyone chooses to do this, but it feels pretty essential to me, and pretty much for the same reason as mapping the `Caps lock` key to `Control`. The `alt` (or `option` key) is just less accessible than the `Command` key on macs. Not only is `Command` a bigger key, it’s also closer to the space bar which makes it much more comfortable to reach without awkward hand contortions.
This change needs to be made in your Emacs configuration. To re-map meta to the command key, just add the following in your `.emacs.d`:
(setq mac-option-modifier 'super)
(setq mac-command-modifier 'meta)
Using Return as control when held down
I got this little nugget from the excellent emacs-redux blog. This one is just awesome. Basically, it sets up `Return` to be `Control` when it is held down for a certain amount of time. Initially this sounds like it could be problematic since return is such a commonly used key, but it actually works REALLY well. It creates symmetry on the keyboard allowing you to use control-sequences on either side of the keyboard comfortably.
It requires you to install Karabinder. Once installed, you just need to go into Karabinder’s settings and update the return to `Return to Control_R`.
One thing I did find I had to tweak was how long the delay was. The default delay is actually relatively long. Reducing the delay addresses a number of problems. Besides making the need to hold down return shorter, it fixes an issue where the delete/backspace
key repeat seems to increase high enough to make holding it down not work properly. This is pretty annoying since this is a pretty common thing to do (though many Emacs hackers may just not delete this way :P)
To change this, Go to:
`System Preferences -> Keyboard`, and the look at the `Delay until Repeat` setting in the top-right corner, and push it more in the shorter direction (how much is up to you, I have it on the second-last notch)
OSX Keybinding Gotchas
This one tripped me up. I was trying to figure out why the keybinding C-M-d (move down in a nested s-expression in `smartparens`) wasn’t working. Turns out OSX binds this key-combo (when Meta is set to `Command`) to looking up a word in the dictionary.
There are other global keybindings that can potentially have this problem when you bind Meta to `Command`, so it’s something to be aware of. The fix can be found here.
As far as custom keybindings in Emacs, I generally try to use the default keybindings (whether it’s Emacs or the defaults for a given package) as much as possible. The main reason being you are less likely to have conflicts with new packages you add in the future, or that become integrated into Emacs at a later time (which is not uncommon).
There are however a few exceptions. They mainly fall into categories of actions I perform so frequently and are heavily ingrained in my muscle memory from experience using other editors (such as IntelliJ). If any commands came along which used these as their default keybindings, I would consider these to trump them due to their frequency of use and general ubiquity. This includes things like:
- Searching for files – the vast majority of programs bind this to `Command-Shift-f`, it’s just burned in. It also seems like a nice analog to C-x C-f, which opens files, rather than searches for patterns within them.
- Opening files – Again, commonly bound to `Command-o` or `Command-Shift-o`
- Navigation – IMO, Emacs have awful keybindings for popping the mark (which is how I navigate). C-u C-@ is just way too awkward for something I do so often. I’ve remapped moving backward/forward in mark history to M-[ and M-]. In addition to being symmetrical (like the default bindings), it is much easier to type.