问题
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)?
回答1:
Maybe one of these two plugins is what you need:
- slime is screen-based.
- tslime is a tmux-based version of slime.
回答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.).
回答3:
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
回答4:
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.
回答5:
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 w. And the code will be transmitted to the repl environment.
Look into the github homepage for more details, it will worth your time.
来源:https://stackoverflow.com/questions/7906858/vim-run-selected-code-in-a-persistent-repl-environment