Regular readers will know that when it comes to tinkering with text editors, I can’t leave well enough alone. I’ve used many different editors over the years, but have kept returning at various intervals to Vim. I like Vim a lot, and despite its various inconveniences, I find myself missing modal editing and the ease with which you can move around and edit text when I am using other editors. Despite that, I occasionally drop back into the comforting GUI territory of Sublime Text 2 or Textmate 2, purely because I’ve set up some fancy configuration in Vim, but forgotten to how to use it (or – in extreme cases – that it’s even there). Graphical interfaces may be less efficient, but they have the benefit of discoverability when you aren’t living in a text editor all day.
A few years ago, I got interested in Emacs, mostly because of the superb org-mode. Calling
org-mode a note-taking system is a bit like describing the LHC as a very large circular tunnel. You can do almost anything in
org-mode, including keeping a diary, scheduling things to do, embedding source code that generates graphs via
R, tracking your time, and even writing plain text spreadsheets with formulae. It’s a pretty incredible system, and just gets more impressive the deeper you dive into the manual. However,
org-mode is an Emacs thing, so if you want to use it, you have to use Emacs. I tried, I really did, but Emacs and I just did not see eye to eye. Editing text in a non-modal editor seemed completely inefficient after using Vim, and I could not get used to the seemingly endless and (to me) illogical keyboard commands which seemed to require a few extra fingers than I possess. Ultimately, I felt that Kieran Healey’s characterisation of Emacs as Fangorn was uncomfortably close to the truth1. So I gave up on Emacs, and returned to Vim plus occasional use of other GUI text editors.
Then a few weeks ago, I came across a project called Spacemacs (motto: “The best editor is neither Emacs nor Vim, it’s Emacs and Vim!”). Emacs has had a Vim-emulation package for years called ‘Evil’ (which is what Spacemacs uses), but as with many Vim emulators in other editors, the clashing conventions of the two editors would often cause problems or confusion. Despite being based on Evil, Spacemacs takes a different approach, and rather than jamming a modal editor into a non-modal one, it goes some way to making both Emacs and the emulated Vim within it more modal. The name comes from the fact that it uses the space bar to prefix most commands instead of Emacs’ finger-crippling keyboard combinations. It also has highly discoverable features, because it uses an hierarchical ‘guide-key’ system, whereby hitting the space bar opens a window listing the immediate keyboard shortcuts available, then hitting another key (e.g. ‘w’ for window-related commands), filters the list to keys relevant to those commands. This gives you the discoverability of a menu-driven system, but the efficiency of a keyboard-driven system. As you commit particular commands to your muscle-memory, you can just use the hotkey without looking at the guide-key window. For example, hitting
<space> f e d opens your
.spacemacs config file for editing. A lot of thought has been put into grouping functions logically, and most use a mnemonic key to activate them (e.g. ‘b’ for buffers, ‘p’ for projects, ‘w’ for windows, ‘t’ for toggles etc.).
Spacemacs also sets up ‘micro-states’ which are modal states in which you can issue further commands relating to a particular function, without having to prefix them with other keystrokes. For example, if you are doing a lot of window manipulation, you can hit
<space> w . to enter the windows micro-state, in which you can just hit the relevant keys to move, resize, create or kill windows, without having to prefix those commands. When you have finished, you hit any other key to exit. The modeline changes to show you that you are in the micro-state, and even offers hints about which commands are available. There are also micro-states for searching, pasting and even scrolling the page, all of which improve significantly on the ease of use of such commands in either Vim or Emacs.
Essentially, Spacemacs is a starter kit for Emacs, but one that includes some very clever default configuration and choice of packages, which magically makes it more than the sum of its parts. Helm and Projectile are included, and allow you a
Ctrl-P-like interactive commandline for doing things like finding files, switching projects, searching and so on. These are pre-configured and given a space bar prefix, so you find yourself using them naturally. You can install packages yourself by adding a line to the config file, in a similar way to Vundle in Vim. I’ve installed a few, and can highly recommend the Pandoc-mode package, which is fantastically full-featured and easy to use. You can also write your own configuration ‘layers’, which isn’t too difficult once you’ve worked out the conventions by looking at existing examples of layers. I wrote a tiny one that activates in Markdown files to allow me to hit
<space> om to open the current file in Marked.app. Spacemacs is in very active development, and as a consequence, things sometimes break, but I’m already hooked. I’ve got a lot to learn about configuring and programming Emacs, and also about
org-mode, which was what prompted me to try Emacs originally, but I find that I’m not missing anything about plain Vim, other than the speed with which it starts up.
In fact, the whole thing is wickedly accurate and hilarious. ↩