Giter Club home page Giter Club logo

vim-cellmode's Introduction

Vim-cellmode

This a vim plugin that enables MATLAB-style cell mode execution for python scripts in vim, assuming an ipython interpreter running in screen (or tmux).

Demo

Youtube demo video

Usage

Blocks are delimited by ##, #%% or # %% (customizable through cellmode_cell_delimiter). For example, say you have the following python script :

##
import numpy as np
print 'Hello'                  # (1)
np.zeros(3)
##
if True:
  print 'Yay !'                # (2)
  print 'Foo'                  # (3)
##

If you put your cursor on the line marked with (1) and hit Ctrl-G, the 3 lines in the first cell will be sent to tmux. If you hit Ctrl-B, the same will happen but the cursor will move to the line after the ## (so you can chain Ctrl-B).

You can also select line(s) and hit Ctrl-C to send them to tmux. The plugin automatically deindent selected lines so that the first line has no indentation. So for example if you select the line marked (2) and (3), the print statements will be de-indented and sent to tmux and ipython will correctly run them.

Requirements

On Linux, you need xclip if you want to use screen.

Keys mapping

By default, the following mappings are enabled :

  • C-c sends the currently selected lines to tmux
  • C-g sends the current cell to tmux
  • C-b sends the current cell to tmux, moving to the next one

You can disable default mappings :

let g:cellmode_default_mappings='0'

In addition, there is a function to execute all cells above the current line which isn't bound by default, but you can easily bind it with :

noremap <silent> <C-a> :call RunTmuxPythonAllCellsAbove()<CR>

Options

You have to configure the target tmux/screen session/window/pane. By default, the following is used :

let g:cellmode_tmux_sessionname=''  " Will try to automatically pickup tmux session
let g:cellmode_tmux_windowname=''
let g:cellmode_tmux_panenumber='0'

let g:cellmode_screen_sessionname='ipython'
let g:cellmode_screen_window='0'

This scripts relies on temporary files to send text from vim to tmux. To allow cell execution queuing, we use a rolling buffer of temporary files. You can control the size of the buffer by defining g:cellmode_n_files (10 by default).

To choose between tmux and screen, set g:cellmode_use_tmux=1 (or 0 if you want screen). Note that currently, CopyToScreen relies on OSX' pbcopy to set the paste buffer.

You can also configure the cell delimiter. This is done through the g:cellmode_cell_delimiter_variable (prefix it with b: to only affect the current buffer). This is used inside a regexp so you can use regexp in it. So for example

set g:cellmode_cell_delimiter='\(##\|#%%\|#\s%%\)'

will match ##, #%% and # %% as cell delimiters. This is the default configuration.

Difference with vim-ipython

Note that if you want more advanced integration with IPython (using the new multi-client architecture), there is the vim-ipython project : https://github.com/ivanov/vim-ipython/

The main difference with vim-ipython is that this plugin simply emulate a paste as you would do it manually from vim to ipython. This allow to see the result of the execution directly in the ipython split whereas vim-ipython uses a separate vim buffer to show the results.

License

MIT (see LICENSE)

vim-cellmode's People

Contributors

patnr avatar julienr avatar willwillsiii avatar kdheepak avatar erdiaker avatar hwong557 avatar leetschau avatar nexayq 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.