sponsor Vim development Vim logo Vim Book Ad

vimteractive : Sending commands from vim to interactive programs

 script karma  Rating 9/3, Downloaded by 2545  Comments, bugs, improvements  Vim wiki

created by
Will Handley
 
script type
ftplugin
 
description
*vimteractive.txt*   Sending commands from vim to interactive programs

                    Vimteractive - main help file


==============================================================================
CONTENTS                                               *vimteractive-contents*

    1.Intro........................................|vimteractive-intro|
    2.Usage........................................|vimteractive-usage|
    3.Extending functionality......................|vimteractive-extending|
    4.About........................................|vimteractive-about|
    5.License......................................|vimteractive-license|

==============================================================================
1. Intro                                                  *vimteractive-intro*

Vimteractive was inspired by the workflow of the vim-ipython plugin:

    https://github.com/ivanov/vim-ipython

This plugin is designed to extend a subset of the functionality of vim-ipython
to other interpreters (including ipython). It is based around the unix
philosophy of "do one thing and do it well".  It aims to provide a robust and
simple link between text files and interactive interpreters. Vimteractive will
never aim to do things like autocompletion, leaving that to other, more
developed tools such as YouCompleteMe.

The activating commands are
- ipython |:Iipython|
- python  |:Ipython|
- julia   |:Ijulia|
- maple   |:Imaple|
- bash    |:Ibash|
- clojure |:Iclojure|
- zsh     |:Izsh|

You can also let Vimteractive detect interpreter using |:Iterm| or just send
some lines: Vimteractive will create terminal if needed. Note: it's highly
recommended to use IPython as your default Python interpreter. You can set it
like this:

let g:vimteractive_default_shells = { 'python': 'ipython' }

Default Python REPL support for pasting is really bad and you should use
IPython whenever possible. If you need to use default Python REPL, you must
put newline after every top-level block.

Commands may be sent from a text file to the chosen terminal using CTRL-S.
See |v_CTRL_S| for more details.

Since this package leverages the native vim interactive terminal, it is
only compatible with vim 8 or greater.


==============================================================================
2. Usage                                                  *vimteractive-usage*

To use the key-bindings, you should first disable the CTRL-S default, which is
a terminal command to freeze the output. You can disable this by putting

stty -ixon

into your .bashrc (or equivalent shell profile file)

------------------------------------------------------------------------------
Example usage:

Create a python file "test.py" with the following content:

    import matplotlib.pyplot as plt
    import numpy

    fig, ax = plt.subplots()
    x = numpy.linspace(-2,2,1000)
    y = x**3-x
    ax.plot(x, y)
    ax.set_xlabel('$x$')
    ax.set_ylabel('$y$')

Now start an ipython interpreter in vim with :Iipython. You should see a
preview window open above with your ipython prompt. Position your cursor over
the first line of test.py, and press  CTRL-S. You should see this
line now appear in the first prompt of the preview window. Do the same with
the second and fourth lines. At the fourth line, you should see a figure
appear once it's constructed with plt.subplots(). Continue by sending lines to
the interpreter. You can send multiple lines by doing a visual selection and
pressing CTRL-S.

If you switch windows with CTRL-W k, you will see the terminal buffer switch
to a more usual looking normal-mode buffer, from which you can perform
traditional normal mode commands. However, if you try to insert, you will
enter the terminal, and be able to enter commands interactively into the
prompt as if you had run it in the command line. You can save this buffer if
you wish to a new file if it contains valuable output

By default every buffer is connected to separate terminal. If you want to
connect two buffers to one terminal, use |:Iconn| command.


Supported terminals                                   *vimteractive-terminals*

*:Iipython* Activate an ipython terminal
*:Ipython*   Activate a python terminal
*:Ijulia*   Activate a julia terminal
*:Imaple*   Activate a maple terminal
*:Ibash*     Activate a bash terminal
*:Izsh*     Activate a zsh terminal
*:Iclojure* Activate a clojure terminal
*:Iterm* Activate a terminal based on current filetype

Sending commands                                                    *v_CTRL_S*

CTRL-S sends lines of text to the interpreter in a mode-dependent manner:

In |Normal-mode|, CTRL-S sends the line currently occupied by the cursor
the terminal.

In |Insert-mode|, CTRL-S sends the line currently being edited, and then
returns to insert mode at the same location.

In |Visual-mode|, CTRL-S sends the current selection to the terminal.

ALT-S sends all lines from the start to the current line.

If there is no active terminal for current buffer, CTRL-S will automatically
create one for you using |:Iterm|.

==============================================================================
3. Connecting to existing REPLs             *:Iconn* *vimteractive-connecting*
:Iconn [{buffer}] Connect current buffer to REPL in {buffer}. You can
connect any number of buffers to one REPL. {buffer}
can be omitted if there is only one terminal.

==============================================================================
4. Extending functionality                            *vimteractive-extending*

To add a new interpreter to Vimteractive, you should define
g:vimteractive_commands variable. For example:

let g:vimteractive_commands = { 'pythonasync': 'python -m asyncio' }

will provide you :Ipythonasync command starting Python 3.8+ asyncio REPL.
If you want to make this command default for python filetype, you should do

let g:vimteractive_default_shells = { 'python': 'pythonasync' }

If you see escape sequences appearing when you do CTRL-S for your interpreter,
you may try to disable bracketed paste mode for it:

let g:vimteractive_bracketed_paste = { 'pythonasync': 0 }

If your interpreter has slow-starting REPL (like Clojure), you may want to
wait before sending data to it at the first time. Specify time to wait in
milliseconds like this:

let g:vimteractive_slow_prompt = { 'pythonasync': 200 }

This project is very much in an alpha phase, so if you have any issues that
arise on your system, feel free to contact me:

    williamjameshandley@gmail.com.

==============================================================================
5. About                                          *vimteractive-functionality*

The core maintainer of vimteractive is:

    Will Handley (GitHub: williamjameshandley)

Find the latest version of vimteractive at:

    http://github.com/williamjameshandley/vimteractive

==============================================================================
6. License                                              *vimteractive-license*

Vimteractive is licensed under GPL 3.0
 
install details
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vimteractive.tar.gz 2.4.1 2021-01-10 8.1 Will Handley Bug fix to 2.4.0
vimteractive.tar.gz 2.4.0 2020-12-31 7.0 Will Handley Fix for automatic scroll
vimteractive.tar.gz 2.2.0 2019-12-13 8.0 Will Handley Added support for vertical terminals
vimteractive.tar.gz 2.1.0 2019-11-04 7.0 Will Handley Visual selection improvement
vimteractive.tar.gz 2.0 2019-08-06 8.0 Will Handley Now with multiple terminals
vimteractive.tar.gz 1.7 2019-07-04 7.0 Will Handley Added support for autodetection of terminal types
vimteractive.tar.gz 1.5 2019-06-23 8.0 Will Handley Added julia support
vimteractive.tar.gz 1.1 2018-10-13 8.0 Will Handley Better pasting into ipython
vimteractive.tar.gz 1.0 2018-06-21 7.0 Will Handley Switch from pexpect to native vim terminal
vimteractive.tar.gz 0.2 2018-05-27 8.0 Will Handley Further robustness improvements
vimteractive.tar.gz 0.1 2018-05-27 8.0 Will Handley Initial upload
ip used for rating: 44.220.184.63

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github