Small Clever Rooms
A Vimmer’s Emacs Prerequisites
In a previous post I explained why Vim and Sublime Text ultimately disappointed me; in this one, I’m going to describe how I finally found at least temporary respite in Emacs and what it took to get me there.
I had a rocky start with Emacs. Actually I had about four of them. There was never any question that I was going to use Evil-mode, Emacs’s vi emulation layer. I understand that it arose from the ashes of several previous such efforts to become one of the most complete vi emulations available for any text editor besides ones that derive from vi itself.
Coming from Sublime Text’s deeply inadequate or flawed vi emulation packages, Evil was a revelation. With very few exceptions, it really is just like using Vim. It’s all that other crap that Emacs does that I had to make sense of somehow and that tripped me up the first several times I made a serious attempt at learning it.
One of the popular jokes about Emacs is that it stands for “Escape Meta Alt Control Shift”, a jab at the countless arcane key chords that you’re expected to use to invoke its mind-boggling array of features. Almost immediately, I decided that finding a way to avoid those chords in favor of using Vim-style key sequences mostly without modifiers would be a prerequisite for my using Emacs full time.
To make this distinction a bit clearer: The key command to quit Emacs is
C-x C-c, which means “control-x followed by control-c”. Take a look at this table of Emacs commands and you’ll get an idea why there’s a whole flavor of RSI named for Emacs and why I wanted to just swap those key bindings out from the get go. What I really wanted was to bulk-convert all of Emacs’s RSI-inducing chords to key sequences like ones using Vim’s leader keys: for example, the aforementioned
C-x C-c might become
\xc or something.
My first pass at this had me using god-mode to take a bunch of the modifiers out of Emacs commands. But I had some trouble getting god-mode to play nice with Evil, even when I used the charmingly titled evil-god-state to tie the two together. I suspect that this was actually a perfectly viable way to achieve what I wanted and some misunderstanding on my part prevented me from getting it working; I was too new to Emacs and tried to deviate from its norms too much too fast. If you use evil-mode and god-mode together I’d be interested to hear how it works for you.
By this point I’d dipped my toes into Emacs enough to have a handle on Emacs Lisp, the (far superior to Vimscript) language used to do all of Emacs’s extensive customization. I’d tried the “build up an Emacs config from scratch” thing a couple times and ended up frustrated with it due to its being a total crap shoot whether any given plugin would play nice with evil-mode. So when I came across a starter kit whose tagline is “The best editor is neither Emacs nor Vim, it’s Emacs and Vim!”, and which purports to be “first intended to be used by Vim users who want to go to the next level by using Emacs”, I was 100% ready to jump feet-first into an unabashedly Evil-centric starter kit.
Here’s the link to that starter kit, which is called Spacemacs. It takes Vim’s leader key idea and kicks it into overdrive with the help of a plugin that provides the same functionality in Evil, setting the leader key to space (whence the starter kit’s name) and using it to replace a whole bunch of Emacs chords with modifier-free key sequences.
This approach is pretty similar to the one I had in mind with evil-god-state, though it doesn’t automatically translate Emacs bindings like I’d hoped. But that turned out not to be as big a problem as I thought: Emacs does so much that I don’t really want to have it all at my fingertips. Manually setting up my bindings helps me compartmentalize, adding a few at a time and assimilating them while I note what continues to be most frictionful so I can try to ameliorate it in my next round of bindings. And Spacemacs sets up a ton of bindings for you, using a sort of “namespaced” hierarchy that allows all those bindings to avoid stepping on each other’s toes while also encouraging mnemonics and working well with a nice feature that aids discoverability.
That’s not the only way that Spacemacs is smartly designed. Its overall architecture is such that it’s (relatively) welcoming for the newbie but has a framework for sensible extensibility when you get further into it. I’ll explain some of the things that were most helpful to me in making Emacs with Spacemacs my full-time editor:
Getting Started with Spacemacs
Memorizing these bindings will enable you to get around in Spacemacs, if occasionally somewhat clumsily. They were my bread and butter before I started to do my own configuration. I’m only mentioning Emacs-specific bindings here; note that most of the basic functionality of Vim also works well in Spacemacs, like invoking Ex mode with
: and using it to do things like save and open files, split windows, etc.
<SPC> f f: Mnemonic “find file”. Triggers the function
ido-find-file, which lets you use Ido to navigate your filesystem to find a file to open, starting from the directory of the current buffer. A crash course:
<Tab>will autocomplete. Deleting when there’s no text after a slash will go up a directory.
~/will take you to your home directly from anywhere.
//will take you to your filesystem root from anywhere.
<Return>will go into the selected directory or open the selected file.
<SPC> b s: Mnemonic “buffer switch”. Opens a Helm minibuffer with a list of all your open buffers as well as recently visited ones. The biggest thing to know about Helm is that
<Tab>doesn’t autocomplete. Instead, Helm filters the list as you type and you just select the best match using
<Return>. It does a great deal of more fancy stuff too, but for switching buffers, that will probably suffice.
<SPC> :: no mnemonic, but think of this as the Emacs equivalent of using
:to bring up the Ex command line in Vim. It brings up a Helm buffer that you can use to find an interactive Emacs function to run. There are about thirty million of these and I’m not going to really mention any here, but if you’re reading something about Emacs and you see some hyphen-separated name like
emacs-do-thingit’s probably a function you can call using
<SPC> :. If you’re already familiar with Emacs (or looking at non-Spacemacs-centric Emacs docs), this is the equivalent of the ubiquitous
M-xbinding, but better because of Helm’s fuzzy matching.
<SPC> h d f: Mnemonic “help define function”. Man, so I complained about Vim and Sublime Text in my last post here. Sublime Text’s documentation is mediocre at best whereas Vim’s is very good and thorough, but even after working with Vim’s generally excellent documentation, Emacs’s is a revelation. There’s a reason that the blurb on the official Emacs web page describes it as “the extensible, customizable, self-documenting real-time display editor.” Being able to use this binding, in conjunction with Helm for fuzzy matching, to quickly find any function defined anywhere in Emacs including custom ones, and get generally very useful information about how to use it… it’s amazing how much of a difference it makes in learning how to use Emacs productively. Seriously, learn to love this binding. It even reports any custom bindings that are defined to invoke the function that you’re getting help on.
<SPC> h d k: Mnemonic “help define key”. Another example of Emacs’s excellent built-in help, this binding prompts for more keys and then tells you what they do. If you accidentally hit some key or something doesn’t do what you expect, this binding will tell you what it did. It’s slightly less useful than the previous binding in my experience, but still very useful.
<SPC>: As in, hit the space bar and then just wait. A feature (alluded to above) called guide-key will kick in and list the keys you can use to continue issuing a command, with a short description of what each does. At first most of them will start with “group”; this is the “namespacing” I was referring to earlier. For example, the previous two bindings in this list are in the “help-describe” subgroup of the “helm/help/highlight” top-level group. This hierarchical organization of bindings makes it reasonably plausible that you can discover the binding for a task you want using guide-key alone.
Those bindings, along with Spacemacs’s very good documentation of its own, should be enough to get you started on getting used to the brave new world of Emacs: if you’re a Vim user already, you’re probably familiar with the process of starting with a small set of commands and gradually incorporating new ones into your workflow as you learn where your friction areas are. You’ll have to go through that again with Spacemacs, but having a huge chunk of Vim’s functionality already available makes the process a lot smoother. I know, for example, that there’s a Spacemacs binding for saving a buffer, but I don’t yet know what it is because I always just use the Vim-style
Hopefully that’s enough for you to get started using Spacemacs! It’s a really nice piece of work and it seems to be deservedly catching on like wildfire, so if you’re familiar with Vim and anything I’ve said here sounds appealing, you should give it a try.