Stop Typing Into REPLs

March 16, 2022

Help me help you

When I’m at someone’s desks, in person or virtually, it drives me crazy to see the heroics of typing everything in a REPL

Let alone trying to manually fix broken code on in a REPL…

Or losing their work when exiting the REPL, and trying to grab fragments from the scrollback 😿

It doesn’t have to be like this…

REPLs aren’t perfect…

I ❤️ REPLs and they have great features:

but they also have drawbacks, YMMV:

Since text editors are becoming more interactive (i.e. like IDEs), and computers are generally becoming faster, the advantages of using a REPL have been decreasing over time. It seems common to settle for “whatever, I’ll just run the code…”.

But what if you could have both?

Mixed mode environments

The most obvious example might be a Jupyter notebook

screenshot of jupyter notebook

You mix code cells and their results (whether text, number, graph) and weave, step-by-step, a report/presentation. If you’ve ever used a Jupyter notebook, or seen someone use one, you can see how powerful and liberating it can be.

But, if you’re willing to accept it, Microsoft Excel is probably the embodiment of an interactive programming environment:

screenshot of Excel

Excel formulas are the world’s most widely used programming language.

Microsoft, via The Register

And while these environments might be blissful for specific tasks, they certainly are not general purpose…

Turning EVERY REPL into a “Jupiter notebook”

We already have everything we need:

the REPL does what it’s good for (interactivity, speed, …) and the text editor can focus on its strengths:

What’s missing? You need a way to “send text from the text editor to the REPL”.

Good news if you’re using vim, that’s already available: vim-slime

screenshot of vim-slime

(disclosure: I am the author of vim-slime)

You end up with sessions that look like this:

sample R session

I usually keep my eyes in vim, unless some error message shows up on the right.

What do I use vim-slime for?

From memory, I’ve used vim-slime with:

I haven’t found a REPL where it wasn’t advantageous to “wrap” in vim-slime.

It doesn’t have to be vim-slime…

I understand that vim isn’t for everybody. The other good news is that vim-slime isn’t complicated … most of the work happens when “shelling out”. I don’t see why your favorite text editor couldn’t support this type of workflow.

If you find compelling non-vim alternatives, email me and I’ll include them on this page for others to find.

Discuss on Twitter