问题描述
我想在已经打开的GVim窗口中查看命令的输出.
I want to look at the output of a command in a GVim window that's already opened.
要在新的GVim窗口中查看命令的输出,我要做:
To look at the output of a command in a new GVim window, I'd do:
mycommand | gvim -
要在现有窗口中打开文件,请执行以下操作:
To open a file an existing window, I'd do:
gvim --remote-silent myfile
我如何一起使用它们? mycommand | gvim --remote-silent -
不能不起作用(它认为-
是当前目录中的文件).
How do I use them together? mycommand | gvim --remote-silent -
does not work (it thinks -
is a file in the current directory).
推荐答案
假定您使用默认服务器名称GVIM
运行Gvim,这是一条在运行的Gvim中执行:echo 'It works!'
的命令:
Assume you have Gvim running with default servername GVIM
, here's a command to execute :echo 'It works!'
in the running Gvim:
vim --servername GVIM --remote-send ":echo 'It works!'<CR>"
此命令不返回任何内容,它仅向服务器发送":echo 'It works!'<CR>
"并立即返回.
This command returns nothing, it just sends ":echo 'It works!'<CR>
" to the server and returns immediately.
如果需要评估一个表达式并获取结果,则可以使用以下命令:
If you need to evalute an expression and get the result, you might use this command:
vim --servername GVIM --remote-expr "version"
(将返回版本号)
vim --servername GVIM --remote-expr "2+2"
(将返回"4")
当然,您可以在Vim中声明自己的函数并将其用作表达式,就像这样:
Of course, you can declare your own function in Vim and use it as a expression, just like that:
vim --servername GVIM --remote-expr "MyOwnFunction()"
这篇关于使用--remote时如何向gvim发送命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!