sponsor Vim development Vim logo Vim Book Ad

PyInteractive : Simple python read-eval-print loop inside Vim

 script karma  Rating 80/23, Downloaded by 2026  Comments, bugs, improvements  Vim wiki

created by
Almaz Karimov
 
script type
utility
 
description
This plugin is a simple realization of read-eval-print loop for Python in Vim command window. It requires Python support (see +python) and at least version 2.6 of Python interpreter (you can check python version by running :py import sys; print(sys.version) ).

Features:
- auto-completion (tab)
- auto-indent
- keeps your recent results in the result history, for later user.
- IPython-like magic operators (e.g. object?)
- evaluate selected code
- and more (see the pyinteractive documentation for details)

Demonstration (ver 0.5): http://www.youtube.com/watch?v=oy9Cv3eKy-0&feature=plcp
Project home: https://github.com/clericJ/pyinteractive-vim


Commands:

:PyInteractiveREPL
     Opens an interactive Python console in vim. If you want to finish working with the interpreter,
      press <esc>. Interpreter states are saved between PyInteractive sessions (but not between vim
     sessions), so that if you use PyInteractiveREPL, type x=1 here, close it and then reopen again,
     variable x will still have value 1.

  :PyInteractiveHistory [options]
      Echoes session history.
      Possible options:
           -r          Print history without any formatting (mnemonic: raw)
           -i          Print only input history (mnemonic: input)
           -o          Print only output history (mnemonic: output)
           -f {FILE}   Write history to file {FILE}

:PyInteractiveEval {code}
    Evaluate given code in the interpreter. Command is useful for quickly testing results
    and for scripting purposes (for example, in context menu). Example:
            :PyInteractiveEval def inc(x): return x+1
            :PyInteractiveEval inc(1)
            2
            :PyInteractiveREPL
            >>> inc(10)
            11

  :PyInteractiveRunBuffer
      Execute current buffer in python interpreter and show result.

Autocompletion is defined for PyInteractiveEval command and for input() opened by PyInteractiveREPL command and can be accessed by pressing <tab> key (default, see wildchar if you want to change this).


Examples:

:PyInteractiveREPL
>>> def inc_10(x):
...     return x+10
...
>>> inc_10(7)
17
>>>  import sys
>>> sys.ex<tab> # codecompletion (see pyinteractive-autocompletion)
<built-in function exit>

<ESC>

:PyInteractiveEval inc_10(11) +1
22
:PyInteractiveHistory
in[1]: def inc_10(x):
in[2]:     return x+10
in[3]:
in[4]: inc_10(7)
out[1]: 17
in[5]: import sys
in[6]: sys.exit
out[2]: <built-in function exit>
in[7]: inc_10(11) +1
out[3]: 22
 
install details
Unzip the most recent ZIP archive file (see below) inside your Vim profile directory (usually this is \"~/.vim\" on UNIX and \"%USERPROFILE%\\vimfiles\" on Windows), restart Vim and execute the command \":helptags ~/.vim/doc\" (use \":helptags ~\\vimfiles\\doc\" instead on Windows).
Or use vim-addon-manager (http://www.vim.org/scripts/script.php?script_id=2905)
 

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
pyinteractive-vim.zip 0.7.0 2013-07-14 7.0 Almaz Karimov - Added PyInteractiveEvalRange command
- Added context menu item Evaluate as Python code (for selected text)
- Bugfixes
pyinteractive-vim.zip 0.6.2 2012-02-22 7.2 Almaz Karimov - Added magic command "!" for pretty printing (e.g. sys.modules!)
- Added mapping <c-i> (interpreter call)
- Code reorganization
pyinteractive-vim.zip 0.6.1 2011-10-23 7.2 Almaz Karimov - Added magic command "?" (analog IPython)
- Added magic command "%<" - append intput history to current buffer
- Added magic command "%>" - append output history to current buffer
- In interpreter namespace added vim and sys modules, and _interpreter object
- Fixed error in history output
- Bugfixes
pyinteractive-vim.zip 0.5.4 2011-10-19 7.2 Almaz Karimov - Added command PyInteractiveRunBuffer
- Added PyInteractive menu (Plugin.PyInteractive) and context menu item "Evaluate" (for selected text)
- Added option pyinteractive_add_menu
- Added pyinteractive_add_context_menu
- Added new option "-o" in PyInteractiveHistory command
- Bugfixes
pyinteractive-vim.zip 0.5.3 2010-09-08 7.0 Almaz Karimov Initial upload
ip used for rating: 216.73.216.130

Questions about Vim should go to the maillist. Help Uganda.     Vim at Github