Emacs & Vim

After using Vim for more than four years my recent contacts with Lisp encouraged me to take another look at Emacs. I used to make jokes about Emacs just as Emacs users about Vim but actually it seems to be a pretty decent piece of software.

Being a Vim user in the Clojure community sometimes feels weird. You are happy with Vim. Running Clojure code with right from the editor works well these days. Still you wonder why all those people you consider smart seem to be so committed to Emacs. So I decided to try it once again.


Let's start with a slight rant: I completely do not understand how anyone can use Emacs' default keybindings. Being a Vim user I obviously have a thing for mode-based editing but Emacs' keybindings are beyond my understanding. Some simple movement commands to illustrate this:

Command Emacs Vim
Move cursor down one line Ctrl-n j
Move cursor up one line Ctrl-p k
Move cursor left one character Ctrl-b h
Move cursor right one character Ctrl-f l

These are the commands recommended in the Emacs tutorial (which you open with Ctrl-h t). They are mnemonic, what makes them easy to learn--but is that really the most important factor to consider for commands you will use hundreds of times a day? I don't think so. I tried to convince myself that it might be worth to get used to Emacs' default keybindings but after some time I gave up and installed evil-mode.

Mode-based Editing with Evil Mode

In my memory evil-mode sucked. I was delightfully surprised that it doesn't (anymore?). Evil brings well-done mode based editing to Emacs. As you continue to evolve your Emacs configuration you will most likely install additional packages that bring weird Emacs-style keybindings with them. Since you now have a mode-based editor you can use shorter, easier to remember keybindings to call functions provided by these packages. A useful helper that fits a sweet spot in my Vim-brain is evil-leader which allows you to setup <leader> based keybindings, just like you can do it in Vim:

(evil-leader/set-leader ",")
  "," 'projectile-find-file)

With this I can open a small panel that finds files in my project in a fuzzy way (think Ctrl-p for Vim) hitting , two times instead of Ctrl-c p f.

Batteries Included

What I really enjoyed with Emacs was the fact that a package manager comes right with it. After adding a community maintained package repository to your configuration you have access to some 2000 packages covering Git integration, syntax and spell checking, interactive execution of Clojure code and more. This has been added in a the last major update (v24) after being a community project for some years.


Vim's lack of support for async execution of code has always bugged me and although there are some projects to change this I can't see it being properly fixed at least until NeoVim becomes the go-to Vim implementation. Emacs allows me to kick off commands and do other things until they return. In addition to that it nicely embeds Vim's most notable idea, mode-based editing, very well, allowing me to productively edit text while having a solid base to extend and to interactively write programs.

If you are interested in seeing how all that comes together in my Emacs configuration you can find it on Github.

@martinklepsch, July 2014

Other Posts

  1. Props, Children & Component Lifecycle in ReagentMay 2016
  2. Om/Next Reading ListNovember 2015
  3. Parameterizing ClojureScript BuildsAugust 2015
  4. ClojureBridge BerlinJuly 2015
  5. Managing Local and Project-wide Development Parameters in LeiningenJune 2015
  6. Formal Methods at AmazonApril 2015
  7. (lisp keymap)February 2015
  8. CLJSJS - Use Javascript Libraries in Clojurescript With EaseJanuary 2015
  9. Why Boot is Relevant For The Clojure EcosystemNovember 2014
  10. S3-Beam — Direct Upload to S3 with Clojure & ClojurescriptOctober 2014
  11. Patalyze — An Experiment Exploring Publicly Available Patent DataOctober 2014
  12. Running a Clojure Uberjar inside DockerSeptember 2014
  13. Using core.async and Transducers to upload files from the browser to S3September 2014
  14. Heroku-like Deployment With Dokku And DigitalOceanMarch 2014
  15. Woodworking MasterclassesFebruary 2014
  16. Early Adopters And Inverted Social ProofFebruary 2014
  17. Living SmallFebruary 2014
  18. Sending You a TelegramJanuary 2014
  19. Running a Marathon, Or NotJanuary 2014
  20. Code SimplicityJanuary 2014
  21. What do we need to know?December 2013
  22. Sculley's DiseaseDecember 2013
  23. A Resurrection PostDecember 2013
  24. A Trip To The USSeptember 2013
  25. Analytics DataApril 2013
  26. Asynchronous CommunicationApril 2013
  27. From Zero to Marathon in Six MonthtsMarch 2013
  28. Git Information in Fish Shell’s PromptDecember 2012
  29. When We Build StuffAugust 2012
  30. Models, Operations, Views and EventsJuly 2012
  31. The Twelve Factor AppJune 2012
  32. Paris And BackMay 2012
  33. A Friend Is Looking For A Summer InternshipMay 2012
  34. Kandan Team ChatMay 2012
  35. Startups, This Is How Design WorksMarch 2012
  36. Entypo Icon SetMarch 2012
  37. Hosting A Static Site On Amazon S3February 2012
  38. Exim4 Fix Wrongly Decoded Mail SubjectJanuary 2012