On Friday we had no lessons and I had some free time. I decided to go ahead and wrestle the Emacs vim emulation layer Evil into my Emacs configuration due to having two ideas.

Firstly, I found the xcape utility and an equivalent AutoHotkey script. This allowed me to make my caps lock key have dual functionality: when I hit it it’s escape, and when I hold it it’s control. When previously contemplating returning to vim keybindings in Emacs, I thought that I would need to keep caps lock as control and use something like key-chord.el to have the simultaneous pressing of the j and k keys take me out of insert mode. Since key-chord.el has some quirks, the elegance of the xcape solution made me much more positive about switching.

Secondly, I figured out a sane way to integrate evil-leader.el with buffers in the Emacs state. These are buffers that Evil doesn’t touch, leaving all Emacs bindings intact, generally because the buffers are read-only interfaces rather than text to be edited. Emacs bindings a bunch of keys which would conflict with the useless Vim bindings. For example in my Org agenda buffers there’s nothing to edit, but the t key can be used to mark a todo item as done.

The idea of evil-leader.el is that you can bind all your most used Emacs commands to ordinary letter and number keys, that you activate by first hitting your leader key. So from evil’s normal state (its analogue of vim’s normal mode) I can hit my space bar and then f to open a file using my Emacs interface for doing that. This is much better than Evil’s emulation of vim’s way of opening files (after all, vim is inferior to Emacs for pretty much everything besides editing text).

Now in my Org agenda, space is bound to something useful, so I can’t just bind space as my leader key everywhere. That means I can’t do basic things like switch buffers and open files with the same binding in all buffers: in a normal buffer where vim-emulation is running I use my leader key, and in my Org agenda which is in Evil’s Emacs state, I’d have to use the old Emacs binding. This is totally unacceptable. My solution is to bind <escape><space> to my leader map in Emacs buffers. That’s not too dissimilar to hitting <escape> to get out of insert mode in a vim-emulation buffer, and then using the leader map.

So I went ahead and threw aside almost everything else in my life to hack on Emacs for the past few days to get everything working together well. Three years ago I wrote that switching to Emacs would be really hard and frustrating, and indeed it was. But switching back to vim emulation has turned out to be easy. This is because I’d already built up good habits from Emacs of not scrolling around the buffer by holding down C-n/C-p (or j and k in the vim case), but scrolling screen by screen and then using ace-jump-mode.el to jump to where I need to edit with a few keystrokes, and because my vim knowledge actually seems to have only barely faded away. I’m actually quite decent at both editors.

Even though there are some rough edges to my new setup, I’m already really appreciating how much better the vim modal paradigm is for editing text. I cleaned out my Emacs config and made it much shorter, because I discovered that a great deal of my customisations were just attempts to make Emacs more like vim: better at editing text. Now I just don’t need those. Lots of complexities and anxieties about doing things in the most efficient way, uncomfortable key chords which made me tense up a little each time I used them: all replaced with the quiet zen of the vim editing vocabulary. I’d buried my experience with vim and had forgotten just how good it is. I’ve been subconciously trying to return to it for the past three years. I really didn’t realise that that was what I was doing.

It remains true that I love Emacs and especially Org-mode and there’s no way I’d ever go back to vanilla vim. I’m happy to have the best of both worlds. Now that I don’t have to worry about making Emacs good at editing text, I’ve found myself finding it easier to configure it for the things it is good at. This is because I can be totally confident that Evil will take care of editing, so I can work on my Emacs customisations without thinking about integrating them with Emacs’ editing bindings. Another reason why customisation is easier is that I’m running fewer big chunks of elisp with which I must integrate any customisations I make.

I’ve also made some changes to my desktop keybindings. For a few months I’ve had run-or-raise bindings for Emacs, tmux (Emacs terminals suck, and it’s not worth bashing at it just to make it such a little less, though I do use eshell) and my web browser. That is, I have a key that I can press to either start the program, or switch to its window if it’s already running. Following Xah Lee’s advice, I moved these to the function keys F9–F12 which Emacs is supposed to leave unbound for users to use. I’ve got these working at school. It’s more ergonomic than my previous use of the Super/Windows key, even though it’s a litle slower.

I’ve also banned my usage of C-h and C-m for backspace and return respectively. I’m trying to type more slowly, correct errors just with C-w to delete a word (the Evil version of which is better than vanilla Emacs) and I’m hitting the real return key instead of C-m. I’ve banned them by binding them to no-ops at the level of X11. It’s working well so far and my hands are feeling significantly better.