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)?
Maybe one of these two plugins is what you need:
screen
-based.tmux
-based version of slime.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.).
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With