无法为在 neovim 中运行的程序提供输入

Can't give input to programs ran in neovim

本文关键字:程序 输入 运行 neovim      更新时间:2023-10-16

当我运行用C++或python编写的代码时,我无法为程序提供输入。 对于 C++

#include <stdio.h>
int main(){
int test;
scanf("%d", &test);
printf("%dn", test);
return 0;
}

输出

:!g++ -o run test.cpp && ./run  2>&1| tee /tmp/nvimPNNwAf/3                                                                                            
32767
(1 of 1): 32767

对于 python3

test = input()

输出

:!python3 test.py                                                                                                                                      
Traceback (most recent call last):
File "test.py", line 1, in <module>
test = input()
EOFError: EOF when reading a line
shell returned 1

我知道我可以使用:term它会修复它。但是我在:term上遇到了问题.

当我输入时:

3
10 12 3 9
10 12 7 2
13 11 5 6

它应如下所示:

3
10 12 3 9
10 12 7 2
13 11 5 6
33
-1
83

但是,它输出:

3                       
10 12 3 9    
10 13                   
2 7 2    
13 11 5 6      
1             
1

如何解决此问题? (这在 Vim 中没有发生(

对于您问题的第一部分,这不是一个大功能,而是一个功能,因为在 neovim 中禁用了交互式 shell,您可以在此 GitHub 问题中看到 justimk 答案 https://github.com/neovim/neovim/issues/1496 解决方案是在 neovim 之外调用您的程序或使用插件来执行此操作。