R
G

Back to list2023-222

Good bye Emacs. Hello NeoVim.

Note: Since I wrote this article in early 2023 I made good on my promise to get into Nvim. Check out Nvim related content coming on this site that go into more technical depth. I started with explaining on how to set up debugging for Rust with NeoVim. More will follow soon and linked to here.

When I got started with GNU/Linux I picked Emacs as my terminal editor. It's input first, commands second approach came natural to me and I understood how to use it quite quickly. Vi and Vim on the other hand gave me panic attacks.

Fast forward roughly 25 years I'm finally transitioning away from my beloved Emacs giving in to Vim's dominance. In this post I would like to point out why, how and what kept me from adopting the more popular choice for so long.

Vim vs. Emacs

Choosing a text editor seems to be a rather trivial thing. But if you are serious about your text editing the most minute differences can have a huge impact on your daily workflow.

Vim is the OG text editor on Unix systems. It has been around the longest and has cultivated an insanely large user base. Vi morphed into Vim which eventually morphed into NeoVim. The latter one is my preferred weapon of choice in this transition away from emacs.

Emacs too is an ancient project. Both Vim and Emacs can edit text with great ease. But Vim is truly a text edtor first and nothing else. Emacs on the other hand is often called an OS within your OS. Yes it's a text editor. Yes it's a mail client. Yes it can browse the web. Yes it has a fully functional Tetris clone. Yes it has an inbuilt psychiatrist. Add some extensions and emacs can truly do a lot.

Both editors can be extended to the moon and back. However Vim is the more pure editor experience out of the box.

What sets these editors apart even more is it's command interface. Vim accpts commands first and is an editor second. To edit text the user has to activate the input mode. Emacs on the other hand allows editing first and knows special shortcuts (e.g. Ctrl-X) to enter the command mode for more shortcuts to be executed. Those Emacs shortcuts are now deeply embedded into my mucle memory and are very hard to get rid of even in other tools that know nothing about Emacs.

What kept me from using Vim

Having to enter the edit mode in order to make edits in a text editor is hugely counter intuitive to somebody who comes from a UI based world. This was me all those years ago when I was curious enough about Linux to really push myself into using it as my main OS.

But it was the most minute detail that still drives me crazy on some Vim configurations to this day.

Exiting the input mode is done with the ESC key. This key is supposed to be pressed once which takes you out of the input mode and back into the command mode. My distro of choice back in the day however came with a vim configuration requiring ESC to be hit twice to get out. This was enough to confuse the heck out of my fragile user's mind back then.

Even today I come accross such configs from time to time and it drives me crazy.

Yes this little detail was probably the main reason I was literally scared of vim and used it only in the most desparate cases after which I needed a two week holidy.

So why not stick with Emacs

As you can imagine giving up on an editor is not an easy choice. Muscle memory is a very strong thing to overcome. But Emacs has some of those minute issues as well as some really big ones that annoyed me for a while now.

First the small stuff. By default Emacs spams the file system with backup files. Those Files are easy to spot as they have a trailing tilde (~) in their name. Another type of backup file has nunmber signs (#) around them. Those files are hugely annoying and are the default case in emacs.

Of course this can be switched off. But often I use a console based editor on a foreign system that has no config of mine installed. So I either make some config changes or clean up after myself later.

Speaking of foreign systems. My setups all come with Emacs installed. But systems outside of my control (e.g. customer servers) have no Emacs package installed and rely on Vim or heaven forbid Vi. I have yet to discover a system that has an inverse configuration.

Lastly I'd like to mention speed. Emacs and Vim are both highly versatile and configurable. Entire distrubutions have developed around these editors making them truly epic. For Emacs I currently use Spacemacs with regular Emacs shortcuts.

This distribution is powerful for sure. However startups times of emacs are crushing.

user@system ~ $ time /usr/bin/emacs

real    0m3.647s
user    0m2.561s
sys     0m0.462s

While 3.6 seconds sounds like nothing to extreme it really interrupts your workflow and adds up very fast when you just want to go through files quickly.

Two ways to get around this. First, don't exit Emacs. Easy but hard to forget. Second, my preferred method, just launch Emacs in server mode and connect with the Emacs with the emacsclient command:

user@system ~ $ alias emacs
alias emacs='emacsclient -c'

Using a user service with systemd (~/.config/systemd/user/emacs.service):

[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure

[Install]
WantedBy=default.target

Enabling this service Emacs starts in the background on login.

Two problems. First, I don't do this on every single system I ever touch. Nor is it even possible. CentOS for example does not have a user level systemd mechanism. Second, even this is a bit sluggish at times.

For comparison neovim starting with the AstroNvim configuration package. There is no contest.

user@system ~ $ time nvim -c "q"

real    0m0.039s
user    0m0.022s
sys     0m0.009s

I have many more reasons but listing them all won't do anyone any good.

So let's move on to the painful part.

The pain of switching

While NeoVim has greatly modernized the original Vim and AstroNvim adds a ton of features with almost zero effort on my end there's still one elephant in the room.

Muscle memory. I mentioned this multiple times for a reason. Once you're familiar with an editor so heavily dependant on shortcusts and typed out commands it's hard to switch. This goes any way. Vim users always find Emacs very hard to use. Hence the Evil project adding a VIm feel to the Editor.

If you never used Vim before or only know the bare minumum (open, edit, close) about it, check out vimtutor. This is a little tutorial file instructing you on the use of vim. Whatever you learn about Vim is valid in NeoVim.

Some concepts like using h,j,k,l to navigate around text are very hard to adopt by some users (e.g. me). You can drop them in favor of the arrow keys of course. And there's usually more then one way of getting things done in Vim anyway. However it makes sense to find the most efficient ones that you can manage. Those crazy navigation key mappings have a reason.

Cheatsheets help a ton. This is my preferred Vim Cheatsheet and here's one dedicated to NeoVim

One major advantage of Vim and NeoVim is their community. It's usually much easier to find good and up to date information on how to get things done, install add-ons, enable certain features, etc. then it is with Emacs. With Emacs I often had to struggle a lot to make some config work. Partly because of poor or out of date documentation. Partly because Lisp is a rather unconvential language I find very hard to read.

Bottom line

NeoVim combined with AstroNvim has finally won me over and made me adopt the Vim philosophy seriously. For years I slowly grew more comfortable using NeoVim in it's pure form on various server systems without an extensive Emacs config in place. This made me a lot more comfortable with the concepts and commands behind vim.

Only recently I noticed that I sometimes accidently open nvim when really I intended to type emacs. No biggie. Just edit with vim then and move on.

Seeing how AstronVim turned this already quite good and snappy editor into a deveopment powerhouse in literally five minutes after I discovered it I was hooked.

Looking for a lightweight setup that I can deploy quickly on every sytem this looks like a very promising option. On top of it I don't need any config to have a reasonable default beheavior that won't spam the file system with unwanted trash.

In the end all (good) text editors will produce the same output. It won't matter much if you use Notepad++, Kate, ed, Vim, Emacs, mcedit, nano or any other editor of your choice. It's all about workflow and being comfortable with your choice.

However I'm now living proof that a switch is possible. Muscle memory can be defeated. So if you've ever been eying that other editor that tickles your fancy, just go for it. Give it a good week and see where you can go with that.

Have fun!