Trying vim-slime in Docker

July 8, 2022

(Disclaimer: I wrote vim-slime)

Installing a vim plugin: probably not fun…

Maybe you’ve heard about vim-slime, thought it was cool … but you weren’t sure what you were getting yourself into 🤔

That’s understandable … I feel the same about every vim plugin:

In this case, I propose a “clean slate” experience. Since you probably don’t have a new computer with a fresh OS install lying around, let’s talk about Docker.

Why Docker?

Is Docker perfect? No. (especially on macOS)

What I appreciate about Docker is: the mess stays inside a container. You’re always a few commands (docker rm, docker rmi, docker system prune) away from returning to a known/clean state.

I often have to reproduce problems with combinations of config and tools completely different from how I usually work. I would:

Nothing about this process would “feel good”. Now I try to contain the blast radius inside Docker.

Instructions: vim-slime in Docker

Set up the foundations:

docker run -ti --rm alpine
apk update
apk add vim tmux git

(if, at this point, you’re thinking “why alpine?” … adjust these instructions to your own preferences)

Install vim-slime:

mkdir -p ~/.vim/pack/plugins/start
cd ~/.vim/pack/plugins/start
git clone https://github.com/jpalardy/vim-slime.git
cd # optional, but gets you back $HOME

Configure vim-slime:

echo 'let g:slime_target = "tmux"' > ~/.vim/vimrc

Try vim-slime:

1. start tmux:        tmux
2. split your window: ctrl-b "                 <-- ctrl-b, double-quote
3. start vim:         vim
4: in vim, type:      ls -l / | head -n 10
5: in vim, type:      ctrl-c, ctrl-c           <-- from normal mode

at this point, vim-slime will prompt for your tmux config:
1. "tmux socket name or absolute path: default" -- accept
2. "tmux target pane: :" -- replace ":" with "{last}"

"ls -l / | head -n 10" runs in the other pane (where bash was running)

showing the results of the instructions above

What’s next?

Everything above was “the minimum”; the least number of steps to try vim-slime.
No magic ❌🪄

Some improvements:

A little bit more vim-slime config for your vimrc:

let g:slime_target = "tmux"
let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"}
let g:slime_dont_ask_default = 1

This will use {last} and won’t even ask for you to confirm the config!
(this is how I work)

If you don’t want to use tmux, there are many other options:

See the README for details on how to configure things.

Finally, go step by step – it’s easier to debug that way. And if you need help, open an issue and we’ll figure it out.

Discuss on Twitter