SLIME in Vim

(over 7 years ago)

I've been looking around for a way to have similar basic functionality in Vim as you have with Emacs + SLIME. That is, for all the extra goodies in SLIME, I just want an editing buffer alongside a REPL buffer where executing code and retrieving history is easy. Copying and pasting is annoying, as are REPLs with limited editing functionality (like MIT Scheme's). This requires a decent number of tools, but they're all useful enough that you should probably have them anyway:

brew install git macvim rlwrap screen

(And if you have some other *nix, I'll assume you're smart enough to translate the above. And Windows = ¯\_(ツ)_/¯)

In Vim I use Janus a collection of useful plugins and reasonable defaults. The prerequisites are here if your OS doesn't ship with ruby rake, ctags and ack

Janus provides the ~/.janus folder to add your own plugins, so from there it's just a matter of adding the excellent vim-slime plugin:

cd ~/.janus
git submodule add

Among other things, this will add some SLIME keybindings to Vim, like C-c, C-c for executing the current paragraph in the REPL buffer. vim-slime defaults to using GNU screen, although there are other options, like tmux. It will prompt you for the name of the session and window unless you specify them explicitly, so I use repl for both.

In my .vimrc.after:

let g:slime_paste_file = "$HOME/.slime_paste"
let g:slime_default_config = {"sessionname": "repl", "windowname": "repl"}

In my .zshrc:

alias slimy='screen -S repl -p repl'

This gives you broad flexibility to send code to any interactive utility. For those with readline support, like irb, you just create a new screen session via slimy irb. For stuff like Scheme, I use slimy rlwrap scheme.

For splitting screens I prefer iTerm2 where you can press ⌘D to split vertically. So my workflow looks like this:

  1. Open a terminal session
  2. Open a file with vim or mvim
  3. Press ⌘D
  4. Execute slimy irb
  5. Press ⌘[ to go back to the Vim buffer
  6. Profit

Automating that further is an exercise for the reader (trivial via Alfred).