Vim 新增程序执行窗口,类似于cwindow
我正在使用 Vim 编辑/编译各个 cpp
文件 (makepgr=g++\ -g\ %
),并希望最好使用 这样的快捷键来执行生成的二进制文件F6。然后,所需的行为是打开一个类似于 :cwindow
的新窗口,具有固定的最大高度(例如 20 行),其中包含程序输出。我还希望能够使用另一个快捷键(例如 F7)再次关闭此窗口。
作为奖励,如果程序的执行时间显示在窗口标题/状态中那就太好了。
编辑:我正在谈论的二进制文件是非交互式的!他们主要读取一些输入文件,进行数据操作,将结果写入其他文件,并在这样做时产生一些输出。
I am using Vim to edit/compile individual cpp
files (makepgr=g++\ -g\ %
) and want to execute the resulting binaries ideally using a shortkey like F6. The desired behavior is then, to open a new window similar to :cwindow
with a fixed maximal height (say 20 lines), which contains the program output. I also want to be able to close this window again with another shortkey like F7.
As a bonus, it would be great to have the execution time of the program shown in the windows title/status.
EDIT: the binaries I am talking about are non-interactive! They mostly read some input files, do data manipulation, write their results to other files and have some output while doing so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个小脚本应该可以解决问题:
大部分代码来自 taglist.vim 插件 - 它相当容易理解。
您可以根据您的窗口大小首选项修改
split
命令。This little script should do the trick:
Most of this code came from the taglist.vim plugin - it's reasonably simple to understand.
You can modify the
split
command for your window size preferences.我不确定这是否有任何帮助,因为你问的是 vim:
我首先想到如何解决这个问题是使用 GNU screen。原因不是,vim 无法做到这一点,而是 vim 不能完全用作终端仿真器,因此运行一些交互式程序不起作用。 Plus 屏幕相对容易配置。
我当然会为该任务编写一个专门的屏幕配置。
I'm not sure if this is helpful in any way, since you're asking about vim:
My first thought about how to solve this problem would be usage of GNU screen. Reason is not, that vim isn't capable of doing this, but that vim isn't exactly usable as terminal emulator, so running some interactive programs doesn't work. Plus screen is relatively easy to configure.
I would of course write a specialized screen config for that task.
添加到 vimrc:
打开 vim 并按 F6。您应该在新选项卡中看到命令
ls -la
的输出。现在,如果这对您有用,那么您可以更改它(将 myprog 替换为可执行文件的名称):您甚至可以为此选项卡命名:
不喜欢选项卡?将
tabnew
替换为split
或vsplit
,这样可以水平或垂直分割窗口。想要分割窗口小吗?将5
替换为您喜欢的任何其他数字。还添加了按 F7 关闭选项卡的功能。
PS 您可以将硬编码的
myprog
名称替换为expand("%:r").".exe"
(对于 Windows)或只是expand("% :r")
(对于 *nix)正如已经说过的。Add to the vimrc:
Open vim and press F6. You should see in the new tab with the output of the command
ls -la
. Now, if this works for you then you can change it (replace myprog with the name of your executable):You can even give name to this tab:
Do not like tabs? Replace
tabnew
withsplit
orvsplit
wich allows to split window horizontally or vertically. Want splitted window to be small? UseReplace
5
with any other number you likes. Also addto get ability to close the tab by pressing F7.
P.S. You can replace hard-coded
myprog
name withexpand("%:r").".exe"
(for Windows) or justexpand("%:r")
(for *nix) as already been said.您可以将输入重定向到快速修复窗口(类似于
:make
的工作方式)::cex system(expand("%:r").".exe")
您可以使用
:colder
和:cnewer
浏览快速修复历史记录>我意识到这并不完全是您想要的,但希望它足够接近有用。
You could redirect the input into the quickfix window (similar to how
:make
works)::cex system(expand("%:r").".exe")
You can navigate through quickfix history using
:colder
and:cnewer
I realise this isn't exactly what you were looking for, but hopefully it's near enough to be useful.