Vim to Emacs and Back

Sean
7 min readApr 17, 2021

--

I watched an Emacs video the other day from a dev who moved from Vim and he made a pretty good case for why you might want to make the jump. Plus there’s some things that have been annoying me about Vim lately…

Vim Beefs

My highlighting, linting hack (sad face)

Colors and highlighting. This is an absolute nightmare to get configured in Vim. It might only be an issue because I’m a JS developer and I use .jsx, .tsx, .ts and .js files on a daily basis. I haven’t found a plugin that has a decent and reliable way to deal with syntax highlighting properly highlighting tsx files, getting the colours right breaks the linting and getting the linting right breaks the colours. Instead I’ve had to put a stupid hack in my vimrc to fool my linter into working while having the right colours… which brings me on to…

Linting. I recently changed jobs and was introduced to a new codebase with its own conventions, new file extensions and an eslint config. It took me about a week to get my linter configured. And it’s still sluggish to update, sometimes gets stuck and ugly as sin. Linting is not something I want to spend a long time learning about. I use coc (lol) as my linter and there’s other options but I think the issue is that fundamentally background processes are just something Vim doesn’t like very much.

File exploring. Always a struggle. I’ve got whole other article on this. There’s quite a few options for file exploring in Vim but none of them are quite right. NERDTree tries too much to be like Sublime, Ranger requires a whole external binary and Netrw…well it’s Netrw, just no.

How about Emacs?

I like the idea that Emacs is an Elisp environment and it is written coherently, easy to configure, can draw graphics for nice visual features and comes with its own package manager.

If I want to configure Emacs myself I can do it with Elisp which is Emacs’ own flavour of Lisp. Why is that a plus? Because Lisp is a useful language to know. It’s in wide use having a lot of success through the Clojure framework/library which even has its own version of React templating. Also it’s a purely functional language; I’m a JS programmer and functional skills are hugely portable to Javascript.

And of course a bit of a win for Emacs is Evil mode, a Vim emulator that runs inside Emacs that actually does a pretty good job of emulating it.

Vim emulator’s generally suck, the problem they have is the same problem all emulators have: they’re not the real thing. What can you expect really? Part of Vim’s attraction is that the line between you and Vim’s underlying code base is pretty thin, you can configure it and use it’s internal functions on the go and you can’t really expect an emulator to be able to port that over to completely different platform.

So really you can’t expect an emulator to go much further beyond mapping Vim-like behaviour to it’s keybindings. Evil is the best Vim emulation I’ve come across but even though it’s pretty close, it still falls a little short.

The guys building Evil mode have done a great job, they’ve gotten a load of the functionality you’d expect and it almost feels like you’re using Vim natively but there’s a few niggling issues I have with it.

Emacs Evil Mode Beefs

  1. Jumps. A little talked about feature of Vim but actually the one that first attracted me to th program which I quickly couldn’t do without and surprisingly you don’t find in any other editor. Evil mode has jumps but they’re glitchy. Sometimes forward jump doesn’t work, or it’ll forget the jump history or you might find it jumps you to the bottom of the page you can’t jump out of it again.
  2. Passing registers as variables. Ever done this: :let @+ = @%? Vim has a mixture of default registers and custom one's which you can use like variables to swap their values around. This let's me put the % register (which is set the filepath) to the + register so I can paste the filepath in another program somewhere. Evil mode flat out can't do this, it doesn't have any concept of let and it's register implementation is only skin deep.
  3. Consistency. Evil is a “main mode” in Emacs and sometimes you’ll have to use a different main mode for something else (file directories and the package manager for example have their own modes), suddenly you’re back in Emacs key-binding world. You can only use one main mode at a time in Emacs so to get around this there’s a plethora of minor mode Evil packages out there that cater for different major modes which you have to cherry pick and install separately. The problem here is that, once you start using Evil you’re not quite using Emacs and you have to allow Evil to manage all your key bindings, this makes the process confusing when you want to remap something global, like remapping the leader key for example.

General Emacs Beefs

I suppose it’s pretty unfair for me to say Emacs isn’t as good at being Vim as Vim is but to be honest I’ve spent a lot of time learning Vim’s keystrokes and there’s no reason for me to move away from them. Especially when the alternative is Emacs’ key commands, which brings me to my first issue…

  1. Emacs’ key commands. Like most text editors Emacs doesn’t have a “normal” mode like Vim where you can enter key commands without pressing any mod keys, but Emacs still has just as many different key commands as Vim. Instead it uses ctrl. You find yourself using ctrl over and over again and loads of devs have complained about locking fingers and hand cramps because of this. Emacs was designed for a different keyboard layout which had the ctrl key in the alt key position, this was back in the 70s when the type of keyboard computers might use was still in question. Emacs just backed the wrong horse.
  2. Folder and file managers. Emacs has a great fuzzy matching list menu package called Helm which can be ported to manage any kind of menu picking fuzzy matching functionality you need. Install it and you get a new wrapper around Emacs’ native M-x command for viewing all commands. Helm also has some file and folder management commands which let you search for files in certain directories or projects or buffers or in the current buffer. It has so many commands and different ways of searching that it’ll make your head spin. Then there’s Projectile which links to Helm and allows it to automatically detect if you’re in a git repo and makes that a “project” which you can then search through, and then you can have multiple projects to work on at once and it has a whole host of other commands all prefixed with helm-projectile as well as the commands for just helm or projectile. But it's too much, I don't need that many lists. Vim has a great plugin called vim fzf which can fuzzy search through directories, files, git repos, it's a buffer manager, a window manager, tab manager, you can even fuzzy search through your marks, and each one has a simple command that opens it up, you don't have to cross implement fuzzy finder with a menu system or a project management system because it just works.
  3. Indentation. Yep it’s a nightmare, I’ve no idea why, I’m sure there’s a good reason, I don’t care what it is.
  4. Help. Vim’s help system is very well thought out and easy to understand. If you want to look up a subject in the help you just put :help subject-of-interest, if you want to search through the help you do the same but with :helpginstead. You can follow links to different subjects and they're all placed in an order that makes sense. On the other hand Emacs' doc-mode is a pain. First off you have a whole different mode for docs, with it's own set of key commands, so you have to learn them to use it. Also Emacs ships with different versions of it's docs depending on what version you get, I found my Macos version has the full Emacs manual but my linux version has a Linux manual and no Emacs manual, which I assume I'm supposed to install separately! What a nonsense.
  5. Shell, term, ansi-term, eshell. These are all the different shells that work in Emacs. They all do different things and none of them work like my native terminal so without another configuration rabbit-hole they’re useless to me. The latest version of Vim ships with a :terminal command and it just works.

Conclusion

I used to be a musician and I bought a drum machine called the Korg EM1 which totally revolutionised my way of working with music. It was an excellent but limited drum machine and I soon felt that I’d outgrown it. So I decided to move on to more advanced and expensive devices, of course they where never as good and I wasted a lot of time and money.

Is it time to start diving deeper into Vim, learning Vimscript, writing my own plugins to address the problems I have with it? Yeah maybe.

--

--

Responses (3)