Neovim:如何将钥匙发送到终端模拟器

发布于 2025-01-27 15:33:49 字数 262 浏览 2 评论 0原文

当我打开NVIM终端模拟器并输入以下命令时,尝试执行命令“ python”:

:normal! ipython

事实证明,寄存器内容粘贴到了屏幕上,就好像在正常模式下按了“ p”,即使'i i i'已经在(据说)输入终端插入模式之前按下。

这也无济于事:

:execute "normal! ipython\<CR>"

我在哪里出了问题,我该怎么做正确的?

When I open up a nvim terminal emulator and enter the following command, trying to execute command 'python':

:normal! ipython

It turned out the register content is pasted onto the screen, as if 'p' is pressed under normal mode, even if 'i' has been pressed in prior to (supposedly) enter terminal-insert mode.

This does not help either:

:execute "normal! ipython\<CR>"

Where have I gone wrong, and how could I do it correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怕倦 2025-02-03 15:33:49

feedkeys() 解决问题。因此,在正常模式下在终端缓冲区中执行以下命令在提示上产生“ Python”,就像用户键入:

:call feedkeys('ipython')

feedkeys() solves the issue. So executing the following command in terminal buffer in normal mode produce "python" on the prompt as if typed by the user:

:call feedkeys('ipython')
梦里南柯 2025-02-03 15:33:49
:normal! ipython

并不意味着“运行程序”。它的意思是“切换到正常模式并运行”,这是 filter命令;然后运行i,即切换到插入模式并插入“ Python”。

从VIM命令行运行命令使用

:!ipython
:normal! ipython

doesn't mean "run the program". It means "switch to Normal mode and run !" which is a filter command; then run i that is switch to Insert mode and insert "python".

To run a command from the vim command line use

:!ipython
回眸一遍 2025-02-03 15:33:49

我建议您使用feedkeys(),因为它需要您考虑切换模式,避免映射和逃脱。另外,由于其缓冲性(win_gotoid(term_window); feedkeys(“ als \&lt; cr&gt;”); win_gotoid(current_window)将插入“ ls” ls“ ls”,此外当前窗口,没有一个终端)。

更好的解决方案是使用chansend(window_channel,“ ls \ n”),您可以从b:terminal_job_id中找到通道号。

I recommend against feedkeys() as it requires you to consider switching modes, avoiding mapping and escaping. Plus it cannot be used on non-current window due to its buffered nature (win_gotoid(term_window); feedkeys("als\<CR>"); win_gotoid(current_window) will insert "ls" in current window, not one with terminal).

Better solution is to use chansend(window_channel, "ls\n" ), you can find the channel number from b:terminal_job_id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文