Interact wtih the terminal, or REPL(Read-Eval-Print Loop), in vim 8.1 especially for Python programming. Theoretically, it can also be used for bash and other languages. The main feature is sending the commands to the console and execute without considering the indent problem !
Advantages compared with other similar plugins
- installation and configuration are so easy without any effort.
- support multiple languages, including
Python
,bash
- support virtual environment of
Python
naturally, which can be verified by following steps- activate one
venv
, - open a
*.py
usingvim
- type
:terminal
to open a built-in terminal - type
pip show numpy
(or other packages), which can list the location of package. Using the location to tell whether it's in the virtual environment or not
- activate one
Copy the content in vimrc
to the vim config file, eg~/.vimrc
.
After the installation, there are two ways to open the ipython
console:
- open the console with
--no-autoindent
, for example
:terminal ipython3 --no-autoindent
Otherwise this plugin can't work properly!
- open the console with built-in command
:Ip3
which is controlled by the following config
command Ip3 terminal ipython3 --no-autoindent
command P3 terminal python3
So, you can change the alias by yourself
The short cut is <leader>s
.
- in
normal mode
: typing<leader>s
will send the current line to the console and execute - in
visual mode
: typing<leader>s
will send the selected lines to the console and execute - in
visual mode
: typing<leader>j
will just send the selected content, which can be a few words in one line or several lines, to the console without executing
example send commands with indent bash command
- Fix the blank lines issue when sending code blocks into
Python
console. Detail can be refered from Copy-paste into Python interactive interpreter and indentation, Python interactive interpreter has problems with blank lines when I paste in a script [duplicate], Blank line rule at interactive prompt and How to automatically insert spaces to make empty lines in Python files indent? - Fix the indent issue in
ipython
: can't send long code blocks toipython
console. The reason is explained in jpalardy/vim-slime. The magic function inipython
can't reach the target, which is explained in Turn off IPython autoindent on submit #71. The way to solve the issue is : disable the autoindent inipython
- Add new feature : just sending the selected content to the console without executing