Code Monkey home page Code Monkey logo

vimteractive's Introduction

Vimteractive

vimteractive:send commands from text files to interactive programs via vim
Author: Will Handley
Version: 2.5.0
Homepage:https://github.com/williamjameshandley/vimteractive
Documentation::help vimteractive

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

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". Vimteractive 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 or TabNine <https://tabnine.com>`.

The activating commands are

  • ipython :Iipython
  • julia :Ijulia
  • maple :Imaple
  • mathematica :Imathematica
  • bash :Ibash
  • zsh :Izsh
  • python :Ipython
  • clojure :Iclojure
  • apl :Iapl
  • autodetect based on filetype :Iterm

Commands may be sent from a text file to the chosen terminal using CTRL-S. If there is no terminal, CTRL-S will automatically open one for you using :Iterm.

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' }

Installation

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

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).

Installation should be relatively painless via the usual routes such as Vundle, Pathogen or the vim 8 native package manager (:help packages). If you're masochistic enough to use Arch/Manjaro, you can install vimteractive via the aur. For old-school users, there is also a package on the vim repo. Depending on your package manager, you may need to run :helptags <path/to/repo/docs> to install the help documentation.

Motivation

IPython and Jupyter are excellent tools for exploratory analyses in python. They leverage the interactivity of the python kernel to allow you to keep results of calculations in memory whilst developing further code to process them.

However, I can't stand typing into anything other than vim. Anywhere else, my screen fills with hjklEB, or worse, I close the window with a careless <C-w>. I want a technique that allows me to operate on plain text files, but still be able to work interactively with the interpreter with minimal effort.

Many Projects achieve this with a varying level of functionality. Vimteractive aims to create the simplest tool for sending things from text to interpreter, and making it easy to add additional interpreters. In particular, my main aim in starting this was to get a vim-ipython like interface to the command line maple.

Usage

Example usage:

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

You may want to send lines to one terminal from two buffers. To achieve that, run :Iconn <buffer_name> where <buffer_name> is a name of buffer containing terminal. If there is only one terminal, you can use just :Iconn.

Supported terminals

  • :Iipython Activate an ipython terminal
  • :Ijulia Activate a julia terminal
  • :Imaple Activate a maple terminal
  • :Imathematica Activate a mathematica terminal
  • :Ibash Activate a bash terminal
  • :Izsh Activate a zsh terminal
  • :Ipython Activate a python terminal
  • :Iclojure Activate a clojure terminal
  • :Iapl Activate an apl terminal
  • :Iterm Activate default terminal for this filetype

Sending commands

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.

Connecting to an existing terminal

:Iconn [{buffer] connects 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.

Common issues

Bracketed paste

If you see strange symbols like ^[[200~ when sending lines to your new interpreter, you may be on an older system which does not have bracketed paste enabled, or have other shell misbehaviour issues. You can change the default setting with

let g:vimteractive_bracketed_paste_default = 0

Options

These options can be put in your .vimrc, or run manually as desired:

let g:vimteractive_vertical = 1        " Vertically split terminals
let g:vimteractive_autostart = 0       " Don't start terminals by default

Extending functionality

This project is very much in an beta phase, so if you have any issues that arise on your system, feel free to leave an issue or create a fork and pull request with your proposed changes

You can easily add your interpreter to Vimteractive, using the following code in your .vimrc:

" Mapping from Vimterpreter command to shell command
" This would give you :Iasyncpython command
let g:vimteractive_commands = {
    \ 'asyncpython': 'python3 -m asyncio'
    \ }

" If you see strange symbols like ^[[200~ when sending lines
" to your new interpreter, disable bracketed paste for it.
" You can also try it when your shell is misbehaving some way.
" It's needed for any standard Python REPL including
" python3 -m asyncio
let g:vimteractive_bracketed_paste = {
    \ 'asyncpython': 0
    \ }

" If you want to set interpreter as default (used by :Iterm),
" map filetype to it. If not set, :Iterm will use interpreter
" named same with filetype.
let g:vimteractive_default_shells = {
    \ 'python': 'asyncpython'
    \ }

" If your interpreter startup time is big, you may want to
" wait before sending commands. Set time in milliseconds in
" this dict to do it. This is not needed for python3, but
" can be useful for other REPLs like Clojure.
let g:vimteractive_slow_prompt = {
    \ 'asyncpython': 200
    \ }

Similar projects

Changelist

v2.2:

Vertical splitting option

v2.1:

Visual selection improvement

v2.0:

Multiple terminal functionality

v1.7:

Autodetection of terminals

v1.6:

CtrlP bugfix

v1.5:

Added julia support

v1.4:

Buffer rename

v1.3:

Added zsh support

v1.2:
  • no line numbers in terminal window
v1.1:
  • Bracketed paste seems to fix most of ipython issues.
  • ALT-S sends all lines from start to current line.

vimteractive's People

Contributors

brothert avatar ettom avatar fruzsinaagocs avatar goldsteine avatar protivinsky avatar williamjameshandley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vimteractive's Issues

Support for multiple terminals at once

At the moment, vimteractive only allows one active terminal. In theory one could have multiple active terminals, if there is a use-case for it, for example

  • if you were running different filetypes in different buffers, you could have commands sent to the terminal buffer with the appropriate filetype
  • if you were running multiple terminals of the same filetype, perhaps buffers could be pinned to specific terminals

Any thoughts as to how useful this would be/ideas that might enhance such a system would be appreciated from people that actively use this package:

@brothert @GoldsteinE @fruzsinaagocs
(tag anybody else who might be interested)

Possible errors in autoload/vimteractive.vim

Problem description

Having installed vimteractive with the native package manager (vim 8+), with a working :help vimteractive to verify the installation, I get the following error when running :Iipython or any other vimteractive command (:I*):

Screenshot from 2019-09-09 15-00-59

Setup

  • ubuntu 18.04.3
  • vim 8.0.1453

A solution?

The errors seemed to be in autoload/vimteractive.vim.

  1. First (and this may be wrong), I don't think vim script supports default values of arguments like bufname = ''. I changed this to just bufname in the relevant line, which seemed to have made the first error disappear.
  2. term_kill wasn't actually used in its enclosing function, so I just deleted the line it appeared in.

After these changes, vimteractive seemed to be working again, but I haven't tried any of the new features of version 2.0.

backspace (in insert mode) frozen after having sent lines to interactive program

Description of issue:

In insert mode, pressing backspace doesn't delete some characters.

When does it occur?

It happens after one has sent a line (ctrl+s) to the interactive program of choice, then tries to edit the same line in insert mode. The following characters cannot be deleted with backspace:

  1. those written prior to sending the line and entering insert mode (since the last ctrl+s). This makes it impossible to edit a line and re-send it to the interactive program.
  2. those written between having sent the line to the interactive program, and exiting then re-entering insert mode (esc + i). This makes it impossible to write new lines "in several turns", i.e. whilst switching between command and insert modes.

However:

  • sometimes appending to these characters first in insert mode then lets you delete them,
  • one can still edit any line in command mode .

To reproduce the issue:

  1. Write any line.
  2. Enter command mode and open maple: :Imaple.
  3. Send line to maple: ctrl+S.
  4. Enter insert mode and try deleting some characters in the line (issue 1 above)
  5. Write a new line below the previous one.
  6. Exit insert mode and re-enter it: esc and i.
  7. Try deleting some characters in the second line (issue 2 above).

No new line on windows

I tried to replicate the example in the read me on Windows 10 and it looks like the new line character is not recognized:

image

Buffer name choice causing error.

Naming the buffer used for the repl "Vimteractive" causes false positive when you have the documentation open (also called "Vimteractive") in another buffer.

feature request: wolfram support

Mathematica also has a command-line interface (accessible by typing wolfram in the terminal) and can accept scripts (<filename>.wls files). Will there be support for this in the future?

Vertical split

Hi,
I am new to VIM so this may be an obvious one.
I prefer vertical split to horizontal split, but the default :Ijulia (I use Julia) open the terminal in a horizontal split.

I tried :vert Ijulia, but it also opens Julia in a horizontal split.

Thanks!

EDIT: :vertical ball works.

+terminal

might add to the README to indicate this flag is needed when vim is compiled. i got this error using vim version 8.0.1283 on OS X:

Error detected while processing function vimteractive#term_start:
line    2:
Your version of vim is not compiled with +terminal. Cannot use vimteractive
Press ENTER or type command to continue

Prevent automatic scroll on switching splits

Switching between vim splits causes vimteractive session to scroll to the bottom - which doesn't happen in usual vim terminal.

While reading stack traces for errors with REPL opened in vimteractive, this causes a big problem. I took a quick look through the plugin files but can't see the reason for this. How to fix it (at least temporarily?)

By the way, a great plugin. It's very simple.

Three issues with respect to user-friendly

This is the plugin I have searched for weeks when I use Python. But I find three issues after I installed the plugin and began to use

  • I use python 3.6, not python 2.7, so I don't install ipython2.7, but the plugin try to open ipython2.7 by default. Actually this is not a problem, I can avoid this by modify the source code easily. The issue is when you type Iipython and you don't install ipython2.7, the plugin will freeze your whole vim program! You have to kill the progress!

  • This issue come along with the first one. Since I don't have ipython2.7, I want to open the console by typing terminal ipython3, then send some commands to the console using C-s. But the plugin can't recognize this console and open a new python2.7 console again.

  • The indent issue. In normal mode, the plugin can't send one line which is inside a function or for loop to the console. The error message is unexpected indent.

Can't backspace up to previous line in Insert mode

In an :Iipython session, I can't use backspace to bring my cursor on line n (and the remaining text) up to line n-1 (say after accidentally pressing Enter). I can re-combine lines in (e.g. with C-J), but it's a bit more effort.

P.S. Thanks very much for making vimteractive!

Send results back

It'd be cool if there was possibility to send large command results to Vim in convenient way (e. g. opening for them new buffer). Use case: Python command generated a large JSON, we want to edit it it Vim and load back to interactive console.

Send selected text to Ipython console

This is a great implentation. Thank you for creating this plugin.

Would it be possible to send selected text to the console?
I have tried it but still it sends the whole line where the selected text is.

This feature would be great in situations where one wants to evaluate a small snippet of code without having to switch to the console.

neovim compatible?

I installed vimteractive in neovim v0.4.2, and a command :terminal works fine. But when I run :Iipython, the following error is generated:

Your version of vim is not compiled with +terminal. Cannot use vimteractive

Is vimteractive compatible with neovim?

GitHub page says

vimteractive is only compatible with vim 8 or greater

Does it exclude neovim?

Sending cell of code

Is it possible to send a cell/block of code, delimited by e.g. "##", "%#", or "%%" (Julia, Python and MatLab if I am not mistaken), to the terminal?

If not, concider this a feature request ^_^

Filetype recognition shell

It would be good to implement a filetype recognition so that a single command (e.g. :ITerminal) would activate the appropriate terminal for sending files to, e.g. running this on a buffer with filetype=python would run :Iipython

Interactive plotting broken

In the current version of matplotlib (3.5.2) /ipython (8.4.0) the interactive plotting behaviour has changed. This means that once created, plots do not update (as they are seen to do in the gif)

One fix for this is to run explicitly

import matplotlib.pyplot as plt
plt.ion()

but ideally this would be done with an appropriate set of commands supplied to the ipython --matplotlib interpreter so that it works out of the box.

Can't use ctrl-s in visual mode

Hi Will,
I am having some troubles running ctrl-s in visual mode.
The command ctrl-s works as intended in normal mode and insert mode, but in visual mode it sends what I have in my clipboard to the terminal.

Do you have an idea why? It does the same regardless of the terminal I open (:Ijulia, :Ipython, ...)

Thanks!

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.