Code Monkey home page Code Monkey logo

vim-slime's Introduction

vim-slime

Demo

vim-slime session with R

What is Vim-Slime?

Context for SLIME:

SLIME is an Emacs plugin to turn Emacs into a Lisp IDE. You can type text
in a file, send it to a live REPL, and avoid having to reload all your code
every time you make a change.

Vim-slime is a humble attempt at getting _some_ of these features into Vim.
It works with any REPL and isn't tied to Lisp.

Grab some text and send it to a GNU Screen / tmux / whimrepl / ConEmu session.

VIM ---(text)---> screen / tmux / whimrepl / ConEmu

Presumably, your session contains a REPL, maybe Clojure, R or python. If you can type text into it, vim-slime can send text to it.

The reason you're doing this? Because you want the benefits of a REPL and the benefits of using Vim (familiar environment, syntax highlighting, persistence ...).

More details in the blog post.

Installation

I recommend installing pathogen.vim, and then simply copy and paste:

cd ~/.vim/bundle
git clone git://github.com/jpalardy/vim-slime.git

If you like it the hard way, copy plugin/slime.vim from this repo into ~/.vim/plugin.

Usage

Put your cursor over the text you want to send and type:

C-c, C-c       --- the same as slime

You can just hold Ctrl and double-tap c.

The current paragraph, what would be selected if you typed vip, is automatically selected. To control exactly what is sent, you can manually select text before calling vim-slime.

Vim-slime needs to know where to send your text, it will prompt you. Vim-slime will remember your answers and won't prompt you again. But if you need to reconfigure, type:

C-c, v         --- mnemonic: "variables"

or call:

:SlimeConfig

Configuration

GNU Screen

By default, GNU Screen is assumed, you don't have to do anything. If you want to be explicit, you can add this line to your .vimrc:

let g:slime_target = "screen"

Because Screen doesn't accept input from STDIN, a file is used to pipe data between Vim and Screen. By default this file is set to $HOME/.slime_paste. The name of the file used can be configured through a variable:

let g:slime_paste_file = "$HOME/.slime_paste"
" or maybe...
let g:slime_paste_file = tempname()

WARNING: This file is not erased by the plugin and will always contain the last thing you sent over.

When you invoke vim-slime for the first time, you will be prompted for more configuration.

screen session name:

This is what you put in the -S flag, or one of the line from "screen -ls".

screen window name:

This is the window number or name, zero-based.

tmux

Tmux is not the default, to use it you will have to add this line to your .vimrc:

let g:slime_target = "tmux"

Before tmux 2.2, tmux accepted input from STDIN. This doesn't work anymore. To make it work out without explicit config, the default was changed to use a file like screen. By default this file is set to $HOME/.slime_paste. The name of the file used can be configured through a variable:

let g:slime_paste_file = "$HOME/.slime_paste"
" or maybe...
let g:slime_paste_file = tempname()

WARNING: This file is not erased by the plugin and will always contain the last thing you sent over.

When you invoke vim-slime for the first time, you will be prompted for more configuration.

tmux socket name:

If you started tmux with the -L flag, use that same socket name here. If you didn't put anything, the default name is "default".

tmux target pane:

Note that all of these ordinals are 0-indexed by default.

":"     means current window, current pane (a reasonable default)
":i"    means the ith window, current pane
":i.j"  means the ith window, jth pane
"h:i.j" means the tmux session where h is the session identifier
        (either session name or number), the ith window and the jth pane
"%i"    means i refers the pane's unique id

whimrepl

whimrepl is not the default, to use it you will have to add this line to your .vimrc:

let g:slime_target = "whimrepl"

When you invoke vim-slime for the first time, you will be prompted for more configuration.

whimrepl server name

This is the name of the whimrepl server that you wish to target.  whimrepl
displays that name in its banner every time you start up an instance of
whimrepl.

ConEmu

ConEmu is not the default, to use it you will have to add this line to your .vimrc:

let g:slime_target = "conemu"

When you invoke vim-slime for the first time, you will be prompted for more configuration.

ConEmu console server HWND

This is what you put in the -GuiMacro flag. It will be "0" if you didn't put
anything, adressing the active tab/split of the first found ConEmu window.

By default the windows clipboard is used to pass the text to ConEmu. If you experience issues with this, make sure the conemuc executable is in your path.

Advanced Configuration

If you need this, you might as well refer to the code :-)

If you don't want the default key mappings, set:

let g:slime_no_mappings = 1

The default mappings are:

xmap <c-c><c-c> <Plug>SlimeRegionSend
nmap <c-c><c-c> <Plug>SlimeParagraphSend
nmap <c-c>v     <Plug>SlimeConfig

If you want vim-slime to prefill the prompt answers, you can set a default configuration:

" screen:
let b:slime_default_config = {"sessionname": "xxx", "windowname": "0"}

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

If you want vim-slime to bypass the prompt and use the specified default configuration options, set the g:slime_dont_ask_default option:

let g:slime_dont_ask_default = 1

By default, vim-slime will try to restore your cursor position after it runs. If you don't want that behavior, unset the g:slime_preserve_curpos option:

let g:slime_preserve_curpos = 0

Language Support

Vim-slime might have to modify its behavior according to the language or REPL you want to use.

Many languages are supported without modifications, while others might tweak the text without explicit configuration:

  • coffee-script
  • fsharp
  • haskell / lhaskell -- README
  • ocaml
  • python / ipython -- README
  • scala
  • sml

vim-slime's People

Contributors

0 avatar andars avatar caio avatar dariusf avatar dbeecham avatar esamattis avatar ethagnawl avatar gclapperton avatar geertj avatar ianroddis avatar jdiez17 avatar jinyeow avatar jpalardy avatar katusk avatar kevinjqiu avatar ktamas avatar lpil avatar malyn avatar mhoogendoorn avatar munshkr avatar oracal avatar osfameron avatar peterrincker avatar rgrinberg avatar romeovs avatar rwstauner avatar selliera avatar sursh avatar tmhedberg avatar werbitt avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.