简体   繁体   English

如何防止vim bash命令使用全屏?

[英]How can I prevent vim bash commands from using the full screen?

When I execute a bash command from inside a vim window, the results of the command take up the whole screen and the code disappears. 当我从vim窗口内部执行bash命令时,命令的结果占用整个屏幕并且代码消失。 I would like the results of the command to only take up the screen space that it needs. 我希望命令的结果只占用它所需的屏幕空间。 Is this possible? 这可能吗? To clarify I am using the command 澄清我正在使用该命令

:!echo "my command"

I'm familiar with multiple terminal windows, tmux, and iterm. 我熟悉多个终端窗口,tmux和iterm。 I really just want to be able to do it in a vim window without extra plugins if possible. 我真的只是希望能够在没有额外插件的vim窗口中进行,如果可能的话。

Vim switches the terminal back to the original screen (where you started it from); Vim将终端切换回原始屏幕(从哪里开始); Vim itself uses the alternate screen to display its UI without a terminal scrollbar and without affecting the original contents. Vim本身使用备用屏幕显示其UI而没有终端滚动条,并且不会影响原始内容。 There's no way around that implementation detail. 没有办法解决这个实现细节。

You could use GVIM; 你可以使用GVIM; as that one doesn't run in a terminal, it comes with its own (crude) terminal emulation, and that one just appends output at the command-line location; 因为那个不在终端中运行,它带有自己的(原始)终端仿真,并且只是在命令行位置附加输出; the original window contents just scroll out of the view to make space for the shell command output. 原始窗口内容只是从视图中滚出来为shell命令输出腾出空间。 Even with that, you cannot do any interactions while the output is being displayed; 即便如此,在显示输出时也无法进行任何交互; once you acknowledge the prompt, the output is gone. 一旦你确认提示,输出就消失了。

In the terminal, you've already mentioned the possible alternatives. 在终端中,您已经提到了可能的替代方案。 The straightforward solution would be to split the terminal window via screen or tmux , and then have Vim run in one and the shell commands in the other window. 直接的解决方案是通过screentmux拆分终端窗口,然后让Vim运行在一个窗口中,shell命令放在另一个窗口中。 The big advantage here is that you can work on both in parallel and switch back and forth. 这里的一大优势是你可以并行工作并来回切换。

Starting with Vim 8.1, Vim has basic terminal multiplexing built-in; 从Vim 8.1开始,Vim内置了基本的终端多路复用功能; ie you can start a terminal in a Vim window with :terminal and then switch inside Vim using the default window commands. 即你可以使用:terminal terminal在Vim窗口中启动:terminal ,然后使用默认的窗口命令在Vim内部切换。

For Vim 7, without using external terminal multiplexers, all you can do is capturing the shell command's output inside a scratch buffer: 对于Vim 7,不使用外部终端多路复用器,您所能做的就是在暂存缓冲区内捕获shell命令的输出:

:new | 0read !{bash-command}

This is the basic recipe; 这是基本配方; you can extend that with scratch buffer naming, automatic buffer deletion on close, and so on. 您可以使用临时缓冲区命名,关闭时自动缓冲区删除等扩展它。 See this Vim Tips Wiki page for details. 有关详细信息,请参阅此Vim Tips Wiki页面

This works well for non-interactive commands that don't take a long time to execute; 这适用于不需要很长时间执行的非交互式命令; you don't see live output nor what input you type. 您没有看到实时输出,也没有看到您键入的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM