11

R, Python, Scala etc. all come with REPL-environments, which I don't want to miss, however, most of the time editing text in them sucks, so I edit the code in vim, paste it and look at the output and edit the code in vim again.

I can run the current file with !python % and I can run the current line with even more vim magic, however, this will start a new process of the interpreter.

Is it possible to start a REPL and send lines of code to the running REPL (and get the results back, obviously)?

tstenner
  • 10,080
  • 10
  • 57
  • 92
  • What is the magic to sent current or multiple lines and probably even Visual Select to new process ? Or the same REPL ? – Nishant Jun 17 '14 at 10:55
  • 1
    @Nishant See http://vim.wikia.com/wiki/Execute_Python_from_within_current_file – tstenner Jun 17 '14 at 13:27

5 Answers5

11

Maybe one of these two plugins is what you need:

romainl
  • 186,200
  • 21
  • 280
  • 313
2

I recently wrote a plugin for a very similar purpose: vim-notebook which allows the user to keep a background process alive and to make it evaluate part of the current document (and to write the output in the document). It is intended to be used on notebook-style documents containing pieces of code to be evaluated.

Thomas Baruchel
  • 7,236
  • 2
  • 27
  • 46
2

Maybe you can try my plugin vim-repl. It provides a convince repl environment for vim using the vim8 terminal feature.

here is the github homepage: https://github.com/sillybun/vim-repl.

To open the repl environment, just run :REPLToggle or you can even bind it witk key like:

nnoremap <leader>r :REPLToggle<Cr>

To interact with repl, you just select the code and press <leader>w. And the code will be transmitted to the repl environment.

Look into the github homepage for more details, it will worth your time.

2

Try Conque:

""" Conque is a Vim plugin which allows you to run interactive programs, such as bash on linux or powershell.exe on Windows, inside a Vim buffer. """

It can easily be configured to open a Python interpreter, and a key mapping can be used to transfer the current line to it to be executed (F9 for the current line, F10 for the current file etc.).

Jeet
  • 38,594
  • 7
  • 49
  • 56
2

Not for plain-python alone, but if you're using IPython 0.11 or later, take a look at vim-ipython.

Using this plugin, you can send lines or whole files for IPython to execute, and also get back object introspection and word completions in Vim, like what you get with: object?<enter> and object.<tab> in IPython. Additionally, vim-ipython has a "shell" mode, where as you send lines to IPython, you get to see the results those lines produced back in the specialize buffer. See the second screencast on this post

Paul Ivanov
  • 1,984
  • 1
  • 16
  • 14