Summary: Professional Clojure programmers rely on certain features of their editors to help them program. When choosing an editor, it’s important to pick one that has these two important features: REPL integration and structural editing.

The most popular Clojure editor by far is Emacs. Unfortunately, Emacs has a pretty high learning curve. But there are some very good reasons, besides the normal reasons, why Clojure programmers choose Emacs. And Emacs is not the only option. Just about tied for second place are Cursive and vim. The three of these editors have two important features that make them excellent choices for Clojure professionals.

Emacs was inspired by the old Lisp Machines, and so has been the choice of Lisp programmers for a long time. When Clojure came along, Emacs was quickly adapted to programming in it. Today, it stands as the most popular editor according to the most recent (in 2015) Clojure survey.

Cursive is a different take on Clojure editing. It is built as a plugin for IntelliJ, a popular Java IDE. It leans on the IntelliJ framework for intelligent code navigation, refactoring, and project management.

vim is also a popular editor among programmers, favored for its modal editing. It is programmable and there are many plugins that make it very powerful for editing Clojure.

1. REPL Integration

Clojure programmers often practice interactive development. That means programming at the REPL, performing experiments, and generally editing code with a fast feedback cycle. Interactive development helps us achieve a state of flow.

It’s common to run a REPL in the terminal and switch back and forth between the editor and the REPL. But there’s a better way that the three popular editors allow: REPL integration.

REPL integration comes in many flavors, but generally it means having a REPL in your editor, being able to compile code from files, and even looking up documentation (doc strings).

Emacs

Emacs has a package called Cider. It allows you to compile your code, run tests, execute code at the REPL, format your stack traces, and access documentation. It’s a very full-featured Clojure environment.

Cursive

Cursive has many options for using REPLs. You can learn more on this page.

vim

vim has a package called fireplace that handles REPL integration. It lets you compile code, lookup docs, and expand macros.

2. Structural Editing

A lot of people when beginning with Clojure have some problems with the parentheses. It’s understandable since making sure all of them are closed can be a pain. And making sure you’re at the right indentation level is yet another thing to keep in mind.

Yet experienced Clojure programmers don’t focus so much on closing parens. The reason isn’t because they’ve become adept at counting parens. Instead, it’s because the tools they use help them keep all of the parens balanced all the time. Instead of typing character by character, they manipulate entire expressions. These animations show some of the more common structural editing operations.

Emacs

Paredit is the Emacs package for structural editing. These animations are an awesome guide to the keystrokes for the operations. There is also a paredit reference card. It’s a little crowded but it does the job.

Cursive

Cursive has its own brand of structural editing, which is explained in the user guide.

vim

vim’s structural editing plugin is called paredit.vim. It is similar to the other editors.

Bonus: Refactoring

A recent addition to the Clojure editing world is what I’m lumping together under the umbrella of "refactoring". This includes editing features that require a deeper understanding of the code. For instance, changing a deeply nested form into a form that uses a threading macro. Or looking up the uses of a particular function. These are not quite as useful but they are becoming more important as Clojure software grows. Being able to find usages across a project is very powerful when there is a lot of code to look through.

Emacs

Many useful code understanding features come built into Cider. But there is now a growing collection of refactoring commands in an Emacs package known as clj-refactor. You can also get a cheatsheet for it.

Cursive

Cursive was created to take advantage of the IntelliJ platform. It parses your code and understands it at a deep level, which lets you find code that uses a particular function, rename functions across a project, and other powerful features.

vim

vim is lagging behind in this arena. But there are several small attempts at it. I’m confident that it will catch up quickly because there are many users editing Clojure with it.

More information on Emacs

More information on vim

More information on Cursive

Conclusions

Clojure has some very nice editors available. And it’s worth the time to learn how to use their features, especially REPL integration and structural editing. I purposefully left out choosing and learning an editor in LispCast Introduction to Clojure since learning both at the same time can be overwhelming.

Eventually, if you want to be a Clojure professional, learning to use a good editor is a good investment. Another good investment is to subscribe to the PurelyFunctional.tv Online Mentoring program. It includes hours of Clojure courses from beginner to advanced, with more coming out every week.