Last Updated: June 18, 2016
·
5.387K
· junior-ales

Vim-Slime + iTerm2

My problem was: I wanted to run javascript code in command line without leaving vim buffer or running any crazy vimscript. Now that it's solved, I split my screen horizontally, open a node repl in split 1, open a javascript file in split 2 and everytime I want to run the code there I press C-c,C-c and it sends it to node instance in split 1. Check the picture, AWESOMENESS!!!

Picture

I used vim-slime, a vim plugin, to accomplish this but even after reading and rereading a couple of times the documentation of it and googling alot I couldn't make it work with my iTerm2 in Mac OS X.

By the way, this tip is for users of vim-slime that don't use tmux or whimrepl.

Enough of context, let's go to the solution

Go to the screen that will receive the text/command and run:

  • screen -S SCREEN_NAME
  • screen -ls | grep Attached | cut -f2
  • it will return <pid>.SCREEN_NAME
  • screen -X eval "msgwait 0"

Go to the screen that will send the text/command and run:

  • Open Vim
  • Go to the chunk of text you want to send or visually select it
  • press C-c, C-c
  • it will prompt screen session name:
  • type <pid>.SCREEN_NAME from the other screen
  • it will prompt screen window name: 0 press enter

If it doesn't send right away the command, use C-c,C-c again.

3 Responses
Add your response

Well, that's definitely too much overhead you have there.

autocmd FileType javascript map <buffer> <Leader>R :w<CR>:!/usr/bin/env node % <CR>

I prefer something like that in my vimrc. Also, check out https://github.com/xuhdev/SingleCompile

over 1 year ago ·

Thanks man! This single compile is very cool! Comparing your solutions to mine I can see a couple of differences.

Using screen and the code I shared I have different splits|tabs|widows which means my "coding flow" doesn't break (stoping vim > saving > showing the result > coming back to vim).
Besides that, SingleCompile and the vimrc mapping will evaluate the entire file when my solution will give you the ability to evaluate the exact chunk of code you want.

over 1 year ago ·

Thanks so much for putting this. This was the exact problem I was trying to solve.

I'm trying to wrap that initial step all up in a command. If you have any ideas, please let me know.

over 1 year ago ·