Cursive Testing Keyboard Shortcuts

tl;dr Keyboard shortcuts make Clojure TDD quick ’n’ easy.

Cursive is a plugin for IntelliJ’s IDEA that provides a wonderful environment for writing Clojure.

One of the ways it plugs into the IDE doesn’t show up until you’ve configured a REPL. Once your REPL is up and running, you can click in the menu bar’s Tools sub-menu, and then into the Clojure REPL option. If you’re in a test namespace, you’ll see a few test-specific options.

IntelliJ IDEA’s Tools context menu
IntelliJ IDEA’s Tools > REPL context menu

These great tools can be made even greater by binding some keyboard shortcuts to them. Since setting that up wasn’t immediately clear to me, I thought I’d share some notes about it.

First, open the preferences window with ⌘-,.

Second, select the Keymap section.

Third, duplicate one of the default keymaps. On my laptop, I picked Default for macOS. To duplicate it, click the gear icon next to the dropdown and click Duplicate… and give it a name; I called my custom keymap, creatively, “Dan”. (In actual use, that is; the astute reader may observe it’s actually “Pants” in the screenshot below.)

Step four finally gets interesting, because it’s time to actually set up the keyboard shortcuts. IntelliJ has an awful lot of behaviors available, so you’ll likely want to use the filter menu; repl is a good search term.

IntelliJ IDEA’s Keymap Preferences pane

From there, you’ll want to scan for the same items that appear in the tools menu. Right click each item, and select Add Keyboard Shortcut. This is your computer, so do what feels good, but here’s how I like to set it up.

IntelliJ IDEA’s individual keyboard-shortcut settings

Since IntelliJ allows you to add a “second stroke” to your keyboard shortcuts, I take the opportunity to “namespace” my keyboard shortcuts under Option-T (⌥-T). Then I set up a second stroke for each of the three actions:

That last one is where the magic is. 🧙 Since it’s not uncommon for me to do a bit of test-driven development, I can start by kicking off a failing test run with either ⌥-T R or ⌥-T C. Then, as I iterate toward working code, I can tap ⌥-T T (❤️ that lightning-fast double tap) and get rapid feedback.

Tools Used

IntelliJ IDEA
2019.2.4 i(Community Edition)