Vim to Emacs' Evil chaotic migration guide

I’ve been using Vim for 18 years, and for me it was the only option for serious text work (like programming or writing) because I’m totally addicted to modal text editing to the point that I feel crippled when I’ve to edit text in a non-modal editor. You may argue that programming is not about how fast you write and you would be right, but if you can imagine somebody programming on an on screen keyboard on a tablet, you know how modal editor users feel about non modal edition.

But as many Vimmers, I was always curious about Emacs (the enemy in the editor flamewars!), it’s operating-system-in-a-window and the Lisp virtual machines concepts but the non-modal editing and the low quality of the existing modal editing modes compared with Vim made me keep a sane distance from it.

But then, Evil-mode happened. Evil mode is being developed as a perfect Vim emulation for Emacs. Some of its developers have publicly stated that Vim is the model and if something works differently than in Vim it should be marked as a bug. I’ve been hearing very good things about Evil-mode, and when some of my old Vimmers contacts made the switch I knew the mode should be very good.

So two weeks ago I installed Emacs and Evil and started to configure everything to my liking. My first objective was to have an editing environment as efficient as the one I’ve in Vim, with the same plugins and shortcuts. I didn’t expected to really reach that point in a long time, because I heard than Emacs has less plugins than Vim and I expected to have a hard time creating my dotfiles using Elisp. After two weeks of intense investigation, googling, Elisp accelerated learning, reading of other people’s dotfiles and tinkering I can say that I was very wrong. Not only I’ve an environment where I didn’t lost almost anything to my highly-tuned Vim, but I also got gains in some other areas (and I still haven’t started to play with the famous Org mode or Gnus).

This article is a pretty chaotic recollection of bits about how I turned Emacs into my Vim, and then how I improved over it. Most of the items will be bits of Elisp code for the config file or info about plugins. My hope is that this article will be useful to other Vim power users trying Emacs+Evil because I would have loved to find an article like this when I was starting.

This article has been written with the help of lot of random people whose configs, articles an answers I had the luck to land after some internet search, mostly from StackOverflow, GitHub, and random forums. To keep the article clean, I don’t always cite the source of the snippets but you could easily find most of them just googling the code.

You can also check my Emacs’ dotfiles if you’re interested, but remember that these are newbie dotfiles so I’m probably doing something stupid on them. As you’ll see, my config is split between several files. I advise you to don’t do this from the start, but to dump everything into your .emacs file because it is easier to experiment and change a lot when you’re starting (and if you’re a little like me you’ll be playing a lot with your config) and once you’ve more or less settled on a config, split it into categories. Oh, and keep Vim at hand to fix your Emacs config the several times you’ll broke it.

A good Windows version

I’ve to use Windows at work and I was having a lot of problems with the official version of Emacs for Windows (slowness, unstability, huge memory usage spikes…). Reddit’s user tuhdo read about my woes and suggested two versions of third party packages of Windows Emacs. I’ve tested both and I can say that this one is definitively the best and solves all my problems.

Basic Emacs survival keys

If you’re a Vim user after installing Evil you’ll be using Vim-style commands most of the time, but to install Evil first and for some modes where Evil doesn’t work (like the package manager) you’ll need some basic cheatsheet of Emacs commands.

  • C-g (that is Control and g at the same time) to cancel prompts. Later we’ll remap the escape key to do the same which anyone coming from Vim will need to retain its sanity.
  • C-x k to kill (close) a buffer. Automatically opened windows are usually closeable with “q”.
  • C-x o (that’s an “o” not a zero) to rotate between window
  • C-x 2 to create an horizontal split (window)
  • C-x 3 to create a vertical split
  • M-x (M = Alt on PC) shows the “minibuffer” where you can call Emacs functions. Later I’ll show how to improve it a lot.
  • To toggle long lines wrapping (like set wrap/nowrap in Vim), do M-x visual-line-mode RET.
  • C-y: yank/paste. The only way to paste on the modeline even when you’re using Evil.

Package management

The integrated plugin (package in emacspeak) manager is pretty good. It lists, downloads, updates and install the packages in a breeze. I’ve tested almost all of Vim’s plugin managers and neither of them is close to this. You start it with M-x list-packages (enter to install, d to delet