Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim --remote-expr example

Tags:

vim

Since my google-fu is failing me, can anyone give me a simple example on how to use --remote-expr or any other command line trick to insert text to current buffer, or to set a cfile. (Any : -command would be good.)

All I manage to get with --remote-expr is E449: Invalid expression received for anything.

like image 738
aleator Avatar asked May 29 '11 12:05

aleator


2 Answers

:help E449 leads you to a basic example. Unfortunately it is a bit too basic:

remote_expr({server}, {string} [, {idvar}])

Examples:

:echo remote_expr("gvim", "2+2")
:echo remote_expr("gvim1", "b:current_syntax")

In command line, that turns into

 $ vim --servername "gvim" --remote-expr "2+2"
 4

To get an idea what you can do with expressions, see :help expr.

Ordering Vim to insert text from Command line

You are better off with --remote-send that sends key sequences in similar manner as you'd do with maps or abbrs:

$ vim --servername Foo --remote-send "GoHello world! <ESC>"

will append a new line at the end of the active window's buffer.

like image 103
mike3996 Avatar answered Nov 11 '22 02:11

mike3996


If you want to execute a command, let's say :ls, to get a list of buffers, you can do

vim --servername GVIM --remote-expr "execute(\"ls\")"

This will print the list of all buffers in GVIM server. Note the escaped quotes.

like image 3
Maxim Sloyko Avatar answered Nov 11 '22 00:11

Maxim Sloyko