Spacemacs: Emacs for a Vim Enthusiast

Created: 29th July 2018

For the past three years, I’ve used vim as my primary text editor. I’ve spared no time in proselytising anybody who would listen into using vim too. As you likely know, the two most popular terminal editors are vim and emacs, and there is a long history of their fans feuding. I actually used emacs, for two years before vim. I switched, because I preferred modal editing, where different keys on the keyboard perform different actions based on which mode you are in. This meant, you didn’t keep on having to hit modifier keys to perform special actions, as you would in emacs.

But there were two things I kept on hearing about emacs, that I really wished existed for vim. Firstly, something called org-mode, which is a way of writing notes, tracking tasks and so many other things. While it started out separate from emacs, it is now built in. Secondly, magit, a plugin for dealing with git interactively, rathing than using shell commands. It might seem simple, for similar tools to be built for vim. But the big difference between the editors is their customisability. Emacs is configured in a language called elisp, its own dialect of lisp, making it insanely customisable. The flip side of this, is that it is difficult for users, to make the most of it, without knowing elisp. By constast, Vim has vimscript. It is staightforward to get by using vim, without knowing vimscript. But vimscript isn’t as convenient for writing plugins. The power of emacs, with regard to extensions, led vim fans to refer to is as a “great operating system, lacking only a decent editor”.

Having used vim for so many years, I was not willing to go back and memorise the commands for using emacs. But there was another option, an emacs distribution called Spacemacs. This includes a feature called evil mode, which allows you to use vim keybindings in emacs. You can use evil mode as just another plugin with emacs, but the real selling point of Spacemacs is as a “batteries-included” solution for vim users who wish to work with emacs. The theory goes that Spacemacs has ‘sensible-defaults’ that will satisfy most people, saving them from too much meddling with elisp. Let’s find out if the bold claim on their website holds: “The best editor is neither Emacs nor Vim, it’s Emacs and Vim!”.

Setting Up

Spacemacs was remarkably simple to install:

git clone ~/.emacs.d

The first thing I had to do was figure out how to cope with emacs’ slow startup speed. This is a result of emacs’ customisability, and the fact that Spacemacs includes a lot of packages. It took about 3 seconds, which was even slower than editors such as Visual Studio Code, that use electron. There was a simple solution, which was to take advatange of emacs’ client-server architecture. This means emacs runs as a server, and you can connect and disconnect to it:

emacs --daemon # Run as server in background
emacsclient -nw # Run client

My second task was to add the solarised colour scheme. Most information on the internet is written for somebody with a regular emacs setup. For one, Spacemacs uses its own .spacemacs file not a regular .emacs file. This led to me being rather confused. And of course, since it was only a niche group who use Spacemacs, getting the information I wanted was even more difficult. I had an interesting issue, where it would work correctly without using the daemon, but would display the light solarised colour scheme with the daemon. After much Googling and trying our random pieces of elisp, I was able to fix this. My final issue was regarding line numbers. Since I was using iTerm2, and not the GUI version of emacs, there wasn’t padding between the line numbers and code, by default. Unsurprinsgly, this was solved by a combination of Googling and trial and error.

First Impressions

After solving these issues, I tested editing files with Spacemacs. Straight off the bat, I recognised that it’s vim emulation is extremely good. Simple things such as :wq, movements commands such as gg and hjkl, searching with /searchterm and even substitutions with :%s/search/replacement/g all worked. Like vim, emacs supports splits, but unlike vim, emacs has had support for built-in shells for a long time. Vim only gained this in version 8, and I have seen very few people use it or talk about it. Were I to switch to emacs, this means I could ditch tmux. And this would be fine, since tmux’s other useful feature, session management, is covered by emacs’ client-server capabilities. I use fzf in vim, for fuzzy finding files. Emacs has a similar solution in the form of the package projectile. One thing Spacemacs, does is it provides “evilified” verisons of commands, to match with the modal editing experience.

Org Mode

After this, I started playing around with org-mode. At its core, org-mode is a plain text markup language, that integrates well with emacs. If you wanted to, you could open an org file in another editor, and edit it. But the experience isn’t as nice. Saying org mode looks pretty and the user experience is good doesn’t quite do it justice. It does the little things right. Take the formatting for example. Headings are written in markup as * Heading for the main heading, ** Subheading, for a subheading, etc. But org mode will hide the asteriks and replace them with nice unicode characters. Another example is links. It hides the URL of links, so you only see the description. It lets you have internal and external links, and navigate to them by hitting a key, RET in the case of Spacemacs. That means you can links to other place in your current document, or to other org mode documents and navigate to them easily.

Hopefully, this illustrates to you, that org mode is more than just Markdown. But that’s not all. Org mode is designed around a hierarchial tree structure, and provides special commands for moving subtrees around, creating a new tree at the same level as the one the cursor is on, cloning subtrees, etc. The place where these commands are most useful is with tables. Spacemacs handles automatically aligning tables for you. What’s more, like Excel, the tables can include formulae. Org mode lets you have syntax-highlighted code blocks, but the killer feature is that org mode lets you run the code within the blocks, and place the result in the text file. Think Jupyter notebooks. Because of the tool pandoc, you can easily convert between org mode and other markup languages such as HTML, Markdown and LaTeX. And yes, you can include LaTeX formulae in your org mode documents.

If you think this all sounds cool, you should know that I haven’t even got onto what impressed me the most. The thing that makes org mode amazing, and led me to want to try it out was task management. Org mode lets you make items into tasks. You can add deadlines, with a pretty calendar interface. You can also add checklists. In Spacemacs, the command ,, will toggle whether the current item is checked or not. You can also add a counter that will automatically update, to show how many items have been completed. Then using a feature called org-agenda, you can display a calendar that will take all the data in the files, you’ve told it to look at, and will tell you what tasks you have to do, in a week-by-week.

I should note, that this is only the tip of the iceberg. Because emacs is insanely customisable, so is org mode. I had hoped that org mode would be a total disappointment, thereby reaffirming my belief in vim’s superiority. Alas, that didn’t happen, and I was left very jealous of emacs users. There has been an attempt by vim users, to create something similar called vim-orgmode. While I commend the developers for trying, my experience shows me it is not yet anywhere near the level of quality that emacs’ version is at. But while I liked org mode, using org mode with Spacemacs wasn’t as seamless as I hoped for. Not very many of the commands seemed to have evilified versions, and it was very hard to find which did. A reference sheet would’ve come in very handy, since all the avilable tutorials mentioned the emacs versions, but I preferred to use evilified versions. But that was not all. The commands, { and } did not work with org mode, as I expected them too, which was annoying since they are my main way of navigating files.


The final thing I tried out was magit, the plugin for working with git. This certainly did seem to make using git easier, although I’m not so enthousiastic about it as I am about org mode. The reason being, I could still do everything using the terminal. Some things such as staging only part of a file would be harder, but could be done. The reason it was useful was that it was interactive. You could navigate through the list of changed files with hjkl (because of Spacemacs), and click d to get a diff of what’s changed. The brevity is also convenient; you only had to type in s to stage a change. Unlike, org mode where I could see myself being willing to learn the commands, I don’t think I would be that motivated to learn the commands for magit.

Concluding Thoughts

My foray into emacs was certainly a worthwhile experience. I think it’s good to have experience with different tools, and I’m glad to have finally played around with org mode. I do still prefer vim though. Org mode is just the one thing I wish vim had. But I’m not sure whether dealing with elisp and Spacemacs is worth the trouble.