Giter Club home page Giter Club logo

vim-repl's Introduction

Stand With Ukraine

vim-repl

Introduction

Open the interactive environment with the code you are writing.

Read–Eval–Print Loop (REPL), also known as an interactive toplevel or language shell, is extremely useful in python coding. However, it's difficult to interact with REPL when writing python with vim. Therefore, I write this plugin to provide a better repl environment for coding python or other file in vim. It use the terminal feature for vim8. So your vim version must be no less than 8.0 and support termianl function to use this plugin.

如果您想阅读中文文档,请移步:知乎-vim-repl

Details

usage

Use vim to open a file, run :REPLToggle to open the REPL environment. If the REPL is already open. :REPLToggle will close REPL.

By default, Python Perl and Vimscript are supported. If you run :REPLToggle in a python file, you will get python in the terminal buffer. In a perl file, vim-repl will try to use perlconsole, reply and re.pl (in that order); so one of them should be installed. In a vim file, vim-repl will try to open vim -e. In order to support more languages, you will have to specify which program to run for each specific filetype.

There are three ways to send codes to REPL environment:

  • the first way: stay in normal mode and press <leader>w and the whole line of the cursor will be sent to REPL.

usage

  • The second way is that in normal mode, move the cursor to the first line of one block (start of a function: def functionname(argv):, start of a for/while loop, start of a if-else statement) and press <leader>w, the whole block will be sent to REPL automatically.

usage

  • The third way is to select some lines in visual mode and press <leader>w, the seleted code will be sent to REPL.

usage

  • The last way is to select some word in visual mode and press <leader>w and the selected word will be sent to REPL.

usage

Note: currently this plugin doesn't support NeoVim.

Installation

This plugin support all platforms (Windows, MacOS, Linux). Use your plugin manager of choice.

For MacOS, Windows and Linux Users (vim should have +terminal and +timers support):

  • vim-plug (recommended)
    • Add Plug 'sillybun/vim-repl' to .vimrc
    • Run :PlugInstall

Usage

How to open REPL

:REPLToggle

How to exit REPL

:REPLToggle

If you bind <lead>r to :REPLToggle by nnoremap <leader>r :REPLToggle, you only need to press <leader>r to open or close REPL.

leader key is set by let g:mapleader=' '

How to send code to REPL

  • In Normal Mode, press <leader>w, code in the current line (including leading space and the end center) will be transmitted to REPL
  • In Normal Mode, move the cursor to the begin of a block and press <leader>w and the whole block will be sent to REPL (By default, code block start with def, class, while, for, if will be automatically sent. You can control the definition of start of code block by setting g:repl_auto_sends)
  • In Visual Mode, press <leader>w, selected code (whole line includeing leading space and the last center) will be trasmitted to REPL
  • In Visual Mode, selected a word and press <leader>w, and the selected word will be sent to REPL according to certain rules defined by g:repl_sendvariable_template.

Currently, asynchronous transmission is completed and it is supported for all language if you correctly set the input symbols of the corresponding language. Setting for python is already done by author. Supported command shell for python include python, ipython and ptpython.

Take a typical python REPL environment as an example

>>> 1+1
2
>>> for i in range(3):
...     print(i)
...
>>>

Therefore, the input symbols for python includes '>>>' and '...'. They tell the plugin that it can continue send another line to the REPL environment if the current line of the REPL environment is either '>>>' or '...'. If you want async support for other language aside from python, you have to add entry for this language to g:repl_input_symbols

The default value of g:repl_input_symbols is, the value of the dictionary can be either a list of string or a string:

let g:repl_input_symbols = {
            \   'python': ['>>>', '>>>>', 'ipdb>', 'pdb', '...'],
            \   }

How to switch to REPL environment

You can switch buffer between file and REPL environment the same as change between two vim buffer. press <C-W><C-w> will change between file and REPL environment. <C-w><C-h,j,k,l> also work the way it should be

How to hide the REPL environment

:REPLHide

use REPLUnhide or REPLToggle to reveal the hidden terminal.

How to debug python script?

Note: You should have to install ipdb to debug python script! check it via:

python -m ipdb

if not installed, install it via:

python -m pip install ipdb

The default debugger is python3 -m pip, you can specify it through adding 'python-debug' : '<debugger program, such as ipdb3>' to g:repl_program

I suggest the following key binding:

autocmd Filetype python nnoremap <F12> <Esc>:REPLDebugStopAtCurrentLine<Cr>
autocmd Filetype python nnoremap <F10> <Esc>:REPLPDBN<Cr>
autocmd Filetype python nnoremap <F11> <Esc>:REPLPDBS<Cr>

To debug python code, (don't open python REPL environment via :REPLToggle), move the cursor to certain line and press <F12>, and ipdb will be run and the program will be stopped at that line. Press <F10> will run a single line and Press <F11> will also run a single line but will jump into functions.

usage

How to open python with virtual environment?

There are two ways to open python with virtual environment.

The first method (global) is that put:

g:repl_python_pre_launch_command = 'source /path_to_new_venv/bin/activate'

in .vimrc. And once you toggle python, the following command will be run:

:terminal [g:repl_program['default'][0]/bash/cmd.exe]
source /path_to_new_venv/bin/activate
python/ipython/ptpython

The second method (specific virtual environment) is that put:

#REPLENV: /path_to_new_venv/bin/activate

in python script. If you open this python file with vim and toggle vim-repl, python will be run in specific virtual environment.

How to send python code block seperated by # %% or other tag

If you have the following code seperated into two blocks:

# %%
print(1)
print(2)

# %%
print(3)
print(5)

Just move cursor to some code block and use command :REPLSendSession, whole block will be sent to the REPL environment (e.g. Both print(1) and print(2))

Code block seperator are defined by

let g:repl_code_block_fences = {'python': '# %%', 'zsh': '# %%', 'markdown': '```'}

and g:repl_code_block_fences_end (by default the latter is the same as the former). So if you want to seperate code block by ###, just put:

let g:repl_code_block_fences = {'python': '###', 'zsh': '# %%', 'markdown': '```'}

to .vimrc

If you want to start code block with ### Start and end it with ### End, just put:

let g:repl_code_block_fences = {'python': '### Start', 'zsh': '# %%', 'markdown': '```'}
let g:repl_code_block_fences_end = {'python': '### End', 'zsh': '# %%', 'markdown': '```'}

to .vimrc

How to just send right hand side of current line to REPL environment?

If your cursor is on line, for example:

return [x for x in range(10)]

and you only want to send [x for x in range(10)] to REPL environment and to check result of it, You can use command :REPLSendRHSofCurrentLine<Cr>.

Setting

you can bind the REPLToggle command to a certain key to make it more convenience.

nnoremap <leader>r :REPLToggle<Cr>

g:repl_width

it represents the width of REPL windows. there is no default value.

g:sendtorepl_invoke_key

you can customize the key to send code to REPL environment. The default key is <leader>w

let g:sendtorepl_invoke_key = "<leader>w"

repl_position it controls the location where REPL windows will appear

  • 0 represents bottom
  • 1 represents top
  • 2 represents left
  • 3 represents right
let g:repl_position = 0

repl_stayatrepl_when_open

it controls whether the cursor will return to the current buffer or just stay at the REPL environment when open REPL environment using REPLToggle command

0 represents return back to current file.

1 represents stay in REPL environment.

let g:repl_stayatrepl_when_open = 0

repl_program

It controls which program will be run for certain filetype. If there is no entry in the dictionary, the program specified by "default" will be run. If there is no "default" entry, "bash" will be the choice.

let g:repl_program = {
			\	'python': ['python'],
			\	'default': ['bash']
			\	}

For those who use ipython as REPL program: Since ipython 7 and ipython 6 have a big difference, I have to treat them seperately and have to detect the version of ipython by ipython --version which will cause a obvious lagging. You have better to specify version of ipython by setting:

let g:repl_ipython_version = '6'

or

let g:repl_ipython_version = '7.7'

I have tested some version of ipython and find that this plugin cannot work on 7.0.1. Please use version >= 7.1.1

repl_exit_command

It controls the command to exit different repl program correctly. (Notice: exitcommand depends on repl program not filetype of the current file, so if you want to specify exit command for program like 'ipython', please add "ipython": "quit()" in the dictionary)

let g:repl_exit_commands = {
			\	'python': 'quit()',
			\	'bash': 'exit',
			\	'zsh': 'exit',
			\	'default': 'exit',
			\	}

Once user run :REPLToggle when the REPL environment is already open, this plugin will try to close the repl environment by the following step:

  • send a interupt signal <C-C> to the program
  • if the program is not close, then send two \n and the exit_command + \n to the program.
let g:repl_auto_sends = ['class ', 'def ', 'for ', 'if ', 'while ', 'with ', 'async def', '@', 'try']

If g:repl_auto_sends is defined, once user sends a line starts with any pattern contained in the list, whole block will be send automatically.

let g:repl_python_auto_send_unfinish_line = 1

If g:repl_python_auto_send_unfinish_line is set to 1, once user sends a line that is not finished yet, complete line will be send automatically. For example, for codes:

f(1,
        2)

press <leader>w in the first line, f(1,2) will be sent automatically.

let g:repl_cursor_down = 1

If g:repl_cursor_down is 1, once user sends code blocks using visual selection, the cursor will move to the next line of the last line of the code blocks.

let g:repl_python_auto_import = 1

If g:repl_python_auto_import is 1, once user toggle python REPL environment, all import code will be automatically send to the REPL environment

let g:repl_python_automerge = 0

If g:repl_python_automerge is 1, once user sends code which is seperated into multilines, they are combined into one line automatically. For example, if the code is:

a = 1+\
    2+\
    3

, then a = 1+2+3 will be sent to the repl environment instead of three lines.

let g:repl_console_name = 'ZYTREPL'

represents the name for repl console.

let g:repl_vimscript_engine = 0

If your vim doesn't support python or python3, I provides limited supported for it:

  • It works for python and ipython
  • It also works for ptpython but every line of the codes to be send should be complete, which means if you seperate a line of code into two or more lines, the plugin will not handle it correctly.
let g:repl_sendvariable_template = {
            \ 'python': 'print(<input>)',
            \ 'ipython': 'print(<input>)',
            \ 'ptpython': 'print(<input>)',
            \ }

g:repl_sendvariable_template defines how word is sent to REPL. For example, by default, if you select some_variable and presss <leader>w, print(some_variable) will be sent to REPL. You can define your rule with the help of g:repl_sendvariable_template. <input> will be replaced by selected word and then be sent to REPL.

let g:repl_unhide_when_send_lines = 0

If g:repl_unhide_when_send_lines = 1, when REPL is hidden and you want to send lines, REPL environment will be unhiden before the code is sent.

g:repl_output_copy_to_register

If g:repl_output_copy_to_register is set to a letter (a-z), then output of REPL program will be copied to the corresponding register. (Currently only support ipython)

My Configuration for Vim-Repl

Plug 'sillybun/vim-repl'
let g:repl_program = {
            \   'python': 'ipython',
            \   'default': 'zsh',
            \   'r': 'R',
            \   'lua': 'lua',
            \   'vim': 'vim -e',
            \   }
let g:repl_predefine_python = {
            \   'numpy': 'import numpy as np',
            \   'matplotlib': 'from matplotlib import pyplot as plt'
            \   }
let g:repl_cursor_down = 1
let g:repl_python_automerge = 1
let g:repl_ipython_version = '7'
let g:repl_output_copy_to_register = "t"
nnoremap <leader>r :REPLToggle<Cr>
nnoremap <leader>e :REPLSendSession<Cr>
autocmd Filetype python nnoremap <F12> <Esc>:REPLDebugStopAtCurrentLine<Cr>
autocmd Filetype python nnoremap <F10> <Esc>:REPLPDBN<Cr>
autocmd Filetype python nnoremap <F11> <Esc>:REPLPDBS<Cr>
let g:repl_position = 3

Updates

2021.3.23

  • Add support for auto send uncompleted line
  • Fix the bug that continuously send lines to REPL will cause former codes missing.

2020.10.22

  • Add support for auto import package for python file
  • Add support for import from relative path. For example, if in package 'python_package', there are two file 'a.py' and 'b.py' and a __init__.py. If you import 'B.py' in 'A.py' through import .B. Then if you edit A.py using vim and run vim-repl. import .B will be automatically transformed into import python_package.B and be sent to REPL environment.

2020.4.29

  • Add support for mulitiple repl program. Thanks to @roachsinai 's great work.

2019.10.14

  • Add support for python virtual environment.

2019.8.27

  • Set the default program in Windows to cmd.exe

2019.8.16

  • Add support for vimscript REPL.

2019.8.11

  • Add send selected word function and g:repl_sendvariable_template.

2019.8.10

  • vim-repl no longer need the support of vim-async anymore.

2019.8.9

  • Add almost full support for vim without +python or +python3 support.
  • Rewrite vim-async using timer_start
  • Set the default value of g:repl_auto_sends to ['class ', 'def ', 'for ', 'if ', 'while ']
  • Set the default value of g:repl_cursor_down to 1

2019.8.7

  • Fix bug for windows
  • g:repl_cursor_down will also affect SendCurrentLine

2019.8.6

  • Add support for ipython version >= 7

2019.8.3

  • Rewrite the program to format python codes using python language
  • Abandon using C++ to handle python code
  • g:repl_python_automerge is provided.
  • g:repl_console_name is provided
  • Support both python and python3
  • Remove Checkpoint function

2019.5.28

  • Support REPL environment for Windows.

2019.5.14

  • g:repl_cursor_down is provided.

2019.4.27

2018.7.7

  • Use job feature in vim 8.0 to provide better performance.

2018.7.26

  • Add support for temporary hide the terminal window. If the REPL is already open. :REPLToggle will close REPL.

Troubleshooting

  • The python code cannot send porperly to REPL environment

This trouble cann only happen for vim without +python or +python3 support. Without python engine, vim-repl can only use vimscript to manipulate code to be sent, and it now cannot handle code seperated into multilines. For example, the following code cannot be sent porperly.

some_dict = {1:1,
        2:2,
        3:3}
print(some_dict)

You should combine mulitlines code into one line to make the plugin work porperly as following:

some_dict = {1:1, 2:2, 3:3}
print(some_dict)

For vim with +python or +python3 support, this problem will not happen. If it happens, check whether g:repl_vimscript_engine is set to 0. If g:repl_vimscript_engine = 0, there is a bug here. Please report the bug; If g:repl_vimscript_engine=1, search let g:repl_vimscript_engine = 1 in vimrc and remove it.

  • <space>r doesn't work for my vim

<space> in the example mean the leader key. Check the your leader key mapping in vimrc. To set leader key to <space>, add let g:mapleader=' '

  • Error detected while processing function repl#REPLToggle [10].. repl #REPLOpen

The reason of this error is that vim-repl try to open the program which is not installed on your machine. For example, if you havn't install ipython and set g:repl_program['python']=['ipython'], this error will occur.

  • How to change to Normal Mode in REPL environment?

In REPL environment, press <C-W>N. Or you can use the setting:

tnoremap <C-n> <C-w>N
tnoremap <ScrollWheelUp> <C-w>Nk
tnoremap <ScrollWheelDown> <C-w>Nj

And then you can press <C-n> to change to Normal Mode.


If you like my plugin, please give me a star!

vim-repl's People

Contributors

alaiyeshi025 avatar baksili avatar davidegx avatar fvictorio avatar lrittel avatar roachsinai avatar shawsa avatar shiqf avatar sillybun avatar stubbornvegeta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-repl's Issues

normal模式无法发送多行块(visual模式下可以)

vim8.1 version -python +python3
visual模式下选中多行可以正确发送执行,但是normal模式定位在for循环第一行,只能发送第一行,很奇怪。
感觉应该是我自己配置的原因,和其他插件冲突了?想研究一下又没有太多时间,请问我该怎么排查这个问题?(去看那个函数?)如果有您的指点我应该会排查的高效一些。

Customize REPL colors

Running solarized dark in iTerm2 on Mac OS, the REPL window is impossible to read. I'd like to customize what pallet colors are used for it, but I cannot find them.

Any ideas where I can set the background to the usual dark blue, etc.?

image

/usr/bin/zsh: bad option: -+

Describe the bug
After installing the plugin via vim-plug as described in the README.md, I try to launch the REPL using :REPLToggle. I receive the following output:

/usr/bin/zsh: bad option: -+

[Process exited 1]
  • result of :REPLDebugInfo
VIM-REPL, last update: 2019.8.23
Operation System: /usr/bin/zsh: can't open input file: uname
Support python3: 1
Support python: 1
has +terminal: 0
has +timers: 1
3.7.3 (default, Jun 10 2019, 19:10:47)
[GCC 5.4.0 20160609]
REPL program:
{'vim': 'vim -e', 'perl': '/home/dzmitry/.vim/bundle/vim-repl/ftplugin/perl/psh', 'default': 'bash', 'python': 'python'}
REPL exit commands:
{'vim': 'q', 'zsh': 'exit', 'ptpython': 'quit()', 'lua': 'os.exit()', 'default': 'exit', 'bash': 'exit', 'R': 'q()', 'python': 'quit()', 'ipython': 'quit()'}
Current File Type:
Current Type: YTREPL
Current Exit Commands: exit

Additional context
Maybe, the following settings take an effect on the issue:

set shell=zsh
set shellcmdflag=-c

Windows下可视模式选中多行代码执行报错

可视模式下选中多行代码后按w到REPL中执行报错(单行执行正常):

处理 function repl#SendChunkLines[1]..repl#SendLines[12]..repl#GetPythonCode 时发生错误:

E370: 无法加载库 python36.dll

E263: 抱歉,此命令不可用,无法加载 Python 库
default

环境:

  1. 操作系统:Windows 10 家庭版 x64 1803;
  2. Vim版本:8.1,32位;
  3. python版本:3.5.4,32位。

custom exit command ignored for filetype other than python

this plugin cannot identify custom exit command,although setting python and default command is possible.It cannot distinguish other filetypes and keeps using the default exit

my configuration is as follows:

let g:repl_exit_commands = {
\ "python": "quit()",
\ "javascript":'.exit',
\ "cpp":".q",
\ "bash": "exit",
\ "zsh": "exit",
\ "default": "exit",
\ }

Vim8.1 Huge build with gui,BTW

Old config does not work

These configurations do not work after most recent updates and the error message suggests using list:

let g:repl_program = {
            \   'python': 'ipython',
            \   'default': 'zsh',
            \   'r': 'R',
            \   'lua': 'lua',
            \   'vim': 'vim -e',
            \   }

Using list solves the problem:

let g:repl_program = {
            \   'python': ['ipython','python'],
            \   'default': ['zsh'],
            \   'r': ['R'],
            \   'lua': ['lua'],
            \   'vim': ['vim -e']
            \   }

exit commands not set correctly

When I run REPLDebug, the following log is showed:

REPL program
{'zsh': 'zsh', 'gnuplot': 'gnuplot', 'mma': 'MathematicaScript', 'matlab': 'matlab -nodesktop -nosplash', 'default': 'bash', 'python': '/Users/${USERNAME}/ana
conda3/bin/python', 'cpp.root': 'root -l'}
REPL exit commands
{'zsh': 'exit', 'bash': 'exit', 'default': 'exit', 'python': 'quit()'}
Current File Type:
python
Current Type:
/Users/${USERNAME}/anaconda3/bin/python
Current Exit Commands
exit                

replace ${USERNAME} with my username

乱码问题

我想学学scheme,我下载的是chezscheme,编码应该是utf-8,但这个发送过去后,执行的是乱码。

IPython 4.2.1 IndentationError

我有个cygwin的环境,vim8,IPython 4.2.1 (Python 3.6.4)
报告缩进有问题:

比如:\w以下代码:

for i in range(len(scores)):
print(scores[i])

报告:

In [4]: for i in range(len(scores)):
...: print(scores[i])

File "", line 2
print(scores[i])
^
IndentationError: expected an indented block

If you want to paste code into IPython, try the %paste and %cpaste magic functio
ns.

同样的vimrc我在linux下测试没问题。IPython 7.8.0 Python 3.6.4

我没找到方法可以升级ipython, 请问这是不是已知的ipython版本过低造成的问题?

Buffer switching problem

Hi,
Let me start by saying that this is a really cool project I tried today. Thanks for creating this. It seems very practical, however I cannot find a solution to a very common use case - how to switch between code buffers without switching to terminal buffer.

When I switch to another code buffer (:bnext, which I have mapped to tab), eventually it switches to terminal buffer. Once it is in terminal buffer, there is no way out of that! Then I have to exit out of terminal buffer to finally get my other code buffers.

Perhaps, there is already a solution/workaround that I do not know? If not, this will be a very powerful feature I think.

Will this work with Neovim?

I tried to include this using vim-plug but somehow it does not work as expected. Is this implementation specific to vim8?

Thanks!

shift+v多行发送到python错误

Error detected while processing function repl#SendChunkLines[1]..repl#SendLines[12]..repl#GetPythonCode:
line 1:
E319: Sorry, the command is not available in this version: python3 << EOF
line 2:
E492: Not an editor command: import vim
line 4:
E492: Not an editor command: codes = vim.eval("a:lines")
line 5:
E492: Not an editor command: firstline = ''
line 6:
E492: Not an editor command: firstlineno = 0
line 7:
E121: Undefined variable: codes
E15: Invalid expression: codes:
line 11:
E488: Trailing characters: else:
line 17:
E488: Trailing characters: else:
line 25:
E488: Trailing characters: else:
line 37:
E488: Trailing characters: else:
line 45:
E488: Trailing characters: else:
line 48:
E488: Trailing characters: else:
line 55:
E171: Missing :endif
Error detected while processing function repl#SendChunkLines[1]..repl#SendLines[12]..repl#RemoveExtraEmptyLine:
line 1:
E319: Sorry, the command is not available in this version: python3 << EOF
line 2:
E492: Not an editor command: import vim
line 4:
E492: Not an editor command: def GetBlockType(codeblock):
line 5:
E121: Undefined variable: not
E15: Invalid expression: not codeblock:
line 21:
E488: Trailing characters: else:
line 35:
E488: Trailing characters: else:
line 40:
E488: Trailing characters: else:
line 66:

REPL窗口宽度不能固定

比如设置了竖形REPL窗口的宽度
let g:repl_width = 50 "REPL windows width

然后:REPLToggle 启动。 repl窗口出现,宽度50。没问题。
现在在其他窗口做竖分割,repl窗口仍然为50。 没问题
现在关掉其他窗口的分割,repl窗口会自动变宽。
这是vim的问题还是REPL窗口的问题?有办法让这个REPL窗口宽度不自动变化吗?
我希望REPL一直保持着我定义的初始宽度。

Send interrupt

What should I do to interrupt python execution?
If I type C-c while in the buffer running python, it moves to NORMAL mode, but it does not interrupt execution. Is there an alternative shortcut?

Thanks a lot in advance

line continuation

Thanks for this good plugin.

Could you please check the problem as below:

  • First example:
for i in range(5):
    a = i \
        + 1   # here is a tab in this line
    print(a)

The output is : 5
print(a) is executed after the loop is done.

  • Second example:
for i in range(5):
    a = i \
    + 1  # no tab in this line
    print(a)

The output is:
1
2
3
4
5

The REPL can include print(a) in the loop.

Can you reproduce this? If not, this might be caused by my specific settings.

功能建议:运行一个函数内的某些行代码

这个插件实现的很棒,解决了我目前的很多需求。但是在使用的过程中还是有一些小瑕疵。
比如我定义了一个函数:

def test(a, b):
    print (a + b)

如果我选中的是print(a + b)这一行代码,在丢到REPL里面之后,就会报错。因为这一行代码前面有缩进。
有没有什么办法可以实现这种需求呢?还是我对您的插件理解的不够?
或许在把选中文字丢到REPL里面之前,可以先预处理一下,把多余的缩进去掉。

visual 模式报错

我的macvim8 visual 模式报错

E837: This Vim cannot execute :py3 after using :python
E263: Sorry, this command is disabled, the Python library could not be loaded.

不支持多tab,或者多文件操作?

我发现对于简单的应用ok,但是当打开多个文件之后REPLToggle总有问题。。
比如打开文件a.py, REPLToggle 打开运行良好。
然后用多个tab打开多个文件,编辑其他文件。
切换回初始a.py的tab,关闭REPL,再打开,结果所有其他tab中的文件buffer都罗列在了当前运行REPL的tab中。
很容易重现。目前的设计不支持编辑器中有多个文件打开再多个tab?

<leader>w in visual mode not working when use ipython

When use ipython as python repl, ipython will running in the termianl buffer and <leader>w was working well in normal mode, but in visual mode, it can not send code block to repl.

here is the setting

let g:repl_program = {
			\	"python": "ipython",
			\	"default": "bash"
			\	}

By the way, it came when enabled vim-repl

$ vim -V9vim.log
W22: Text found after :endfunction: }}}"Press ENTER or type command to continue

REPL隐藏之后无法显示

Describe the bug

使用REPLHide隐藏buffer之后,无论是REPLToggle还是REPLUnhide均没有办法让RPL再显示。

** REPLDebug 结果**

处理 function <SNR>88_REPLDebugIPDB[6]..repl#REPLOpen 时发生错误:
第  121 行:
E95: 已有缓冲区使用该名称

长时间运行,各种小问题

有时候之前好的。后来\w就不工作了,没有任何反应, 但repl窗口还在,但貌似之间的联系断掉了。
这时候如果ctrlD手工关掉repl,然后再次REPLtoggle,当前buffer就会消失。关掉整个tab重新打开也不成。需要重启vim。。

[feature]增加repl的可选支持

比如,

let g:repl_program = {
            \   'python': ['python', 'ipython']
}

那么在Toggle REPL的时候可以进行选择比如输入1是python,2是‘ipython'。

不匹配的括号会触发vim报错

如何代码括号不匹配,插件会在vim里报错:比如

    for i in range(len(l2)):
        l2[i]=l2[i] % 10
        if l2[i] // 10:
            l2[i+1 += 1
Error detected while processing function repl#SendCurrentLine[10]..repl#SendWholeBlock[14]..repl#SendLines[10]..repl#ToREPLPythonCode:
line   23:
Traceback (most recent call last):
  File "<string>", line 9, in <module>
  File "/home/ping/.vim/bundle/vim-repl/autoload/formatpythoncode.py", line 387, in format_to_repl
    pc.getcode(codes)
  File "/home/ping/.vim/bundle/vim-repl/autoload/formatpythoncode.py", line 37, in getcode
    self.mergeunfinishline()
  File "/home/ping/.vim/bundle/vim-repl/autoload/formatpythoncode.py", line 112, in mergeunfinishline
    tobeadded = self.rawcontents[j]

我觉得应该如实发给repl环境并在那里报错。

Debug python script using Logitech K380 keyboard

I have setted .vimrc as the following and I now using a Logitech K380 keyboard:

autocmd Filetype python nnoremap <F12> <Esc>:REPLDebugStopAtCurrentLine<Cr>
autocmd Filetype python nnoremap <F10> <Esc>:REPLPDBN<Cr>
autocmd Filetype python nnoremap <F11> <Esc>:REPLPDBS<Cr>

I prepared a file as test.py:

def test(a,b):
    c = a
    d = b
return c + d

test(1+2)

I set the cursot at test(1+2).
When I tried to use fn+F10, fn+F11, fn+F12 to debug a python script,
fn + F10: name 'n' is not defined
fn + F11: name 's' is not defined
fn + F12: name 'c' is not defined

Any suggestion?

Thank you very much!

Can vim-repl support normal mode?

As title, Can vim-repl support normal mode?

In normal mode, I can easily do text operation what vim good at like finding key results, copying output...

Sorry if I'm mistaken, and thanks for your hard work!

Slow startup time

Not sure how to help, but I started feeling a lower startup time of my vim. I run the following analysis:

vim --startuptime ~/vimstart.txt

And the slowest plugin by one order of magnitude was unfortunately vim-repl:

636.073  008.571: VimEnter autocommands
649.314  013.237: first screen update
087.969  013.598  008.244: sourcing /home/user/.vim/plugged/nerdtree/plugin/NERD_tree.vim
124.139  015.084  015.084: sourcing /home/user/.vim/plugged/vim-unimpaired/plugin/unimpaired.vim
023.657  022.524  012.355: sourcing /home/user/.vim/plug.vim
068.980  024.817  024.059: sourcing /home/user/.vim/plugged/colorv.vim/autoload/colorv.vim
558.770  025.608  025.579: sourcing /home/user/.vim/plugged/CSApprox/after/plugin/CSApprox.vim
070.913  027.011  002.194: sourcing /home/user/.vim/plugged/colorv.vim/plugin/colorv.vim
037.617  036.505  000.135: sourcing ~/.vim/vimrc
626.575  059.550: opening buffers
525.400  379.236  379.236: sourcing /home/user/.vim/plugged/vim-repl/plugin/default.vim
525.400  379.236  379.236: sourcing /home/user/.vim/plugged/vim-repl/plugin/default.vim

Not sure what might be causing the slow loading time, sorry for not being more helpful.

Swiching from REPL

Describe the bug
It seems I cannot switch from the REPL using my mapping for the switching.
My current mapping is:
nnoremap
nnoremap
nnoremap
nnoremap

Desktop (please complete the following information):
VIM-REPL, last update: 2019.8.23
Operation System: Linux
Support python3: 1
Support python: 0

Additional context
Since I'm quite new with VIM it might be a trivial problem...

How to use python 3 as default environment for REPL

I installed vim-repl on my ubuntu18.04 where both python 2 and python 3 are installed. The Vim is version 8. When I opened the REPL, the default environment was python 2. So how to change it to python 3? Thank you very much.

<leader>w in visual mode not working

I can send single line commands to the Python REPL interpreter w/ w fine but when I do a visual selection it does nothing, no warning, no error, no output. Not sure how to debug this. Any help would be appreciated.

VIM 8.1

A confusing part in Readme

In README

How to send code to REPL
In Normal Mode, press ww, code in the current line (including leading space and the end center) will be transmitted to REPL
In Visual Mode, press ww, selected code (whole line includeing leading space and the last center) will be trasmitted to REPL

In Normal Mode, when I press ww, the cursor just moves to right 2 words. Do I miss something?

No need python prelaunch command.

I think we don't need g:repl_python_pre_launch_command as we could remove g:repl_python_pre_launch_command = 'source /path_to_new_venv/bin/activate'.

Then directly setting to

let g:repl_program = {
			\	'python': '/path_to_new_venv/bin/python',

Am I right? Is there any difference between them?

What's more, below setting make no source verbose on the vim terminal.

Feature Request: Idle-like Run Module Command?

Would it be possible to add a command that

  • resets the interpreter
  • executes the entire source buffer
  • keeps (i.e. does not clear) the previous interpreter output

Basically, I'd like something in VIM that functions like Idle's "Run Module".

debug进入ipdb之后无法再进入正常ipython环境

花了一天自习测了下,插件创意很好!
我遇到一个问题:进入ipdb断点调试之后,关掉ipdb,再调用REPLToggle打算进入常规ipython环境时,会再次调出刚才的ipdb环境。每次都如此。这是设计之中的还是bug?

support for neovim

I'm not sure how much the work is. It just a feature request.

When I use <leader>r to open terminal program, neovim shows the following error.

image

Bug when invoke <leader>w in visual mode

A small test cask when use <leader>w in visual mode
image

The error information
image

In normal mode, <leader>w send one line successfully.

System: OS X 10.11
homebrew vim/macvim

vim --version
VIM - Vi IMproved 8.1 (2018 May 17, compiled May 22 2018 22:49:56)
macOS version
Included patches: 1
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    -tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    -gettext           +netbeans_intg     +timers
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          -toolbar
+cindent           +insert_expand     +path_extra        +user_commands
-clientserver      +job               +perl              +vertsplit
+clipboard         +jumplist          +persistent_undo   +virtualedit
+cmdline_compl     +keymap            +postscript        +visual
+cmdline_hist      +lambda            +printer           +visualextra
+cmdline_info      +langmap           +profile           +viminfo
+comments          +libcall           -python            +vreplace
+conceal           +linebreak         +python3           +wildignore
+cryptv            +lispindent        +quickfix          +wildmenu
+cscope            +listcmds          +reltime           +windows
+cursorbind        +localmap          +rightleft         +writebackup
+cursorshape       -lua               +ruby              -X11
+dialog_con        +menu              +scrollbind        -xfontset
+diff              +mksession         +signs             -xim
+digraphs          +modify_fname      +smartindent       -xpm
-dnd               +mouse             +startuptime       -xsmp
-ebcdic            -mouseshape        +statusline        -xterm_clipboard
+emacs_tags        +mouse_dec         -sun_workshop      -xterm_save
+eval              -mouse_gpm         +syntax
+ex_extra          -mouse_jsbterm     +tag_binary
+extra_search      +mouse_netterm     +tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -framework AppKit   -mmacosx-version-min=10.11 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.26.2/lib/perl5/5.26.2/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc  -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin -lpython3.6m -framework CoreFoundation  -lruby.2.5.1 -lobjc

SendCurrentLine will not send "\n" to the command

Describe the bug
When using \w, it will not send "\n" after current line.

Desktop (please complete the following information):

  • vim --version
    Terminal and timers are all supported.

Additional context
windows 10
vim 8.1 with terminal and timers supported.
vim-repl, 2019.8.17

I can send code to ipython but keep receiving some error message.

I'm on Ubuntu 18.04, vim 8.0, python 3.6.8, IPython 7.9.0, sillybun/vim-repl and sillybun/zytutil plugged. My vim is aliased as " alias vim='vim --servername vim' ".

Using the same settings as the ones shared on the repo home page, which are pasted here:

Plug 'sillybun/vim-repl'
let g:repl_program = {
            \   'python': 'ipython',
            \   'default': 'zsh',
            \   'r': 'R',
            \   'lua': 'lua',
            \   'vim': 'vim -e',
            \   }
let g:repl_predefine_python = {
            \   'numpy': 'import numpy as np',
            \   'matplotlib': 'from matplotlib import pyplot as plt'
            \   }
let g:repl_cursor_down = 1
let g:repl_python_automerge = 1
let g:repl_ipython_version = '7'
nnoremap <leader>r :REPLToggle<Cr>
autocmd Filetype python nnoremap <F12> <Esc>:REPLDebugStopAtCurrentLine<Cr>
autocmd Filetype python nnoremap <F10> <Esc>:REPLPDBN<Cr>
autocmd Filetype python nnoremap <F11> <Esc>:REPLPDBS<Cr>
let g:repl_position = 3

I can send code to IPython but keep receiving some error message showed in the attached picture.

vim-repl-troubleshooting

Ipython magic function support.

Describe the bug

When using %%timeit to get exec time of a code block, like below:

%%timeit
mean, var = 0., 0.
for i in range(1000000):
    x = np.random.randn()
    a = np.random.randn()
    z = np.random.randn()
    m = np.random.randn()
    y = x * a * z * m
    mean += y
    var += y**2
mean / 1000000, math.sqrt(var / 1000000)

Get indent error when using SendLineToREPL(post below).

Screenshots

image

Additional context

From the Traceback like below, can find no spaces(indent) following each \n.

get_ipython().run_cell_magic('timeit', '', 'mean, var = 0., 0.\nfor i in range(1000000):\nx = np.random.randn()\na = np.random.randn()\nz =

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.