从gvim在现有shell中运行命令 [英] Running command in existing shell from gvim

查看:149
本文介绍了从gvim在现有shell中运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一切都从外壳程序开始.例如,我将urxvtzsh一起使用.在那里,我用gvim打开了一些文件.在这种情况下,它是一个LaTeX文件.现在,我需要执行一些命令(用于编译文档,例如pdflatex).

如何从启动gvim的原始外壳中执行该命令?

如果gvim必须打开一个新的外壳一次,然后在该外壳中执行以后每次对指定命令(pdflatex)的调用,这也是可以接受的,尽管我仍然可以手动输入.

直接运行:!pdflatex的问题是,显示了输出,但是如果输出的时间太长,则无法滚动,按回车键后,一切都消失了.

使用shell的想法意味着,默认情况下不必切换窗口焦点.因此,通常我的命令输出是可见的,但是除非发生错误,否则我可以继续在gvim中工作.现在,如果每次我运行命令时都产生一个新的外壳,这种工作流程肯定是不可能的.

解决方案

GVIM不会为启动它的shell保留句柄",而该shell允许它向其发送命令.由于它们是同步执行的,因此您也无法从GVIM启动Shell,不能继续提供命令,同时也要继续在GVIM中工作.

恐怕您必须使用窗口管理器的功能来启动(然后再重新激活)shell窗口,并将命令作为击键发送给它.在Windows上,这可以通过WshShellRun()AppActivate()SendKeys()方法来完成(例如在VBScript中);在Linux上也可能有类似的窗口控制机制.

但是,如果您不介意在您的GVIM(内部具有其所有缺点)中将外壳 包含在内,

It all starts from a shell. For example I am using urxvt with zsh. There I open some file with gvim. In this case it is a LaTeX file. Now I need to execute some command (for compiling the document, e.g.pdflatex).

How can I have the original shell, from where gvim was started, execute that command?

It would also be acceptable if gvim had to open a new shell once and after that execute every future call of the designated command (pdflatex) in that shell, while I can still type in it manually.

The problem with running :!pdflatex directly is, that the output is shown, but if it has gotten too long scrolling is not possible and after I press return, it is all gone.

The idea with using a shell means, that the window focus does not have to switch over by default. So in general the output of my command is visible, but unless an error occurs I can just keep on working in gvim. Now if a new shell was spawned everytime I run the command, this kind of workflow would certainly not be possible.

解决方案

GVIM does not retain a "handle" to the shell that launched it in a way that allows it to send commands back to it. Because of they synchronous execution, you also cannot launch a shell from GVIM, keep feeding it commands while also continue working in GVIM.

I'm afraid you have to use the functionality of your window manager to launch (and then later re-activate) a shell window, and send the commands as keystrokes to it. On Windows, this can be done (e.g. in VBScript) via WshShell's Run(), AppActivate() and SendKeys() methods; there are probably similar mechanisms for window control on Linux, too.

If you don't mind having that shell inside your GVIM (emulated, with all its drawbacks), though, there are plugins that enable that.

这篇关于从gvim在现有shell中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆