vimux-ipy


Ⅰ. 插件描述

To send python code from vim to ipython running within a tmux split (with either visually selected code or with IPython like cells).

Ⅱ. 基本信息

创建日期:  2013-06-18
使用用户:  1
Github星:  11
插件作者:  jason gors

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'jgors/vimux-ipy'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'jgors/vimux-ipy'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'jgors/vimux-ipy'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/jgors/vimux-ipy

Ⅳ. 文档说明

vimux-ipy

This is a vim plugin for added python functionality built on top
of vimux; thus, it assumes
that the vimux plugin is installed as well. Also, it is adapted
from vimux-pyutils,
but I add some features & abstracted away many details to get
everything up and running quicker.

There are two main uses:

  • First, it allows a block of visual-mode selected python code to be
  1. from vim to a tmux buffer split running iPython.
  • Second, "cells" of code can be sent from vim to the running iPython tmux
  1. Regarding this use case, the idea here is to be able to have code
  2. execution similiar to that found in the iPython Notebook, though

being able to stay within vim. Additionally, if the cell_delim
arg (explained below) is set such that it is the same as what the iPython
notebook uses to delimit its code cells, then the script can be uploaded &
opened as an iPython notebook, and the iPython NB environment will
recognize the delimited cell blocks.

The workflow for this would be:

  • start a tmux session,
  • open the desired python script with vim,
  • then execute the command to open the iPython tmux split/pane (eg. Leader vip),
  • now execute code in the tmux pane with iPython by either visually selecting code
  1. send, or send a block of code that is delimited into cells.

A typical session would look like this

(using cells for execution by executing the cell by being inside of that cell and hitting Leader+c):

Key mappings

key mappings that are enabled by placing the following code into .vimrc:

To open the iPython tmux split [Leader vip]:

map <Leader>vip :call VimuxIpy()<CR>

  • Optionally, an argument can be passed into VimuxIpy() to start ipython
  1. a preferred way: eg. VimuxIpy("ipython --pylab"), or VimuxIpy("ipython --profile=some_cool_profile").

If no argument is passed to VimuxIpy(), then normal ipython will start without any flags set.

After the iPython tmux split is created, these keybindings are made:

  • Jump down into the tmux pane in copy(/vim) mode

Leader vi

  • Close the vim tmux split

Leader vx

  • Interrupt any command running in the tmux pane

Leader vq

  • Insert the same cell block delimiter that iPython uses to seperate their
  1. blocks in the iPython notebook [# <codeblock>]

Leader vc


To send & execute visually selected code in the iPython tmux split [Leader e]:

vmap <silent> <Leader>e :python run_visual_code()<CR>


To execute the current "cell" in the iPython tmux split [Leader c]:

noremap <silent> <Leader>c :python run_cell(save_position=False, cell_delim='####')<CR>

Note, a cell is similar to an iPython Notebook code cell and is defined as a code block
spanning from one cell_delim to the next cell_delim (explained below).

Two arguments can be passed into run_cell:

  • save_position: [default False]

    If set True, then the cursor will stay at the current location after the code cell
    is executed. If False, then the cursor will jump ahead to the beginning of
    the next code cell block.

  • cell_delim: [default '####']

    Code cells are delimited by the cell_delim argument -- this specifies what
    should seperate the code cell blocks. Note, there should be a cell_delim
    at the beginning of the first code cell, as well as at the end of the last code cell.

    As mentioned above, this arg can be set such that it is the same as what the
    iPython notebook uses to delimit its code cells: cell_delim='# <codecell>'
    Meaning, if cells are seperated with this as the cell_delim, then the script can
    be uploaded & opened as an iPython notebook, and the iPython NB environment will
    recognize the delimited code cell blocks -- NOTE, in order to be able to upload
    a script delimited in this way to the iPython notebook environment, the first
    thing at the very top of the script needs to be:
    # <nbformat>3</nbformat>

    for more details see:

    ipython notebook format stable

    ipython notebook format dev

添加新评论