Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send commands to gvim when using --remote?

Tags:

vim

pipe

I want to look at the output of a command in a GVim window that's already opened.

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

How do I use them together? mycommand | gvim --remote-silent - does not work (it thinks - is a file in the current directory).

like image 858
Andres Riofrio Avatar asked Apr 25 '12 07:04

Andres Riofrio


2 Answers

Try gvim --remote-silent <(mycommand).

like image 110
Andrew Aylett Avatar answered Oct 25 '22 08:10

Andrew Aylett


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>"

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"

(version number will be returned)

vim --servername GVIM --remote-expr "2+2"

("4" will be returned)

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()"
like image 2
Dmitry Frank Avatar answered Oct 25 '22 09:10

Dmitry Frank