blob: 5b328c1f25bc2523d79984132b670586578dde9c [file] [log] [blame]
Bram Moolenaar54143f42007-05-12 15:10:39 +00001*remote.txt* For Vim version 7.1. Last change: 2006 Apr 30
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Vim client-server communication *client-server*
8
91. Common functionality |clientserver|
102. X11 specific items |x11-clientserver|
113. MS-Windows specific items |w32-clientserver|
12
13{Vi does not have any of these commands}
14
15==============================================================================
161. Common functionality *clientserver*
17
18When compiled with the |+clientserver| option, Vim can act as a command
19server. It accepts messages from a client and executes them. At the same
20time, Vim can function as a client and send commands to a Vim server.
21
22The following command line arguments are available:
23
24 argument meaning ~
25
26 --remote [+{cmd}] {file} ... *--remote*
27 Open the file list in a remote Vim. When
28 there is no Vim server, execute locally.
29 There is one optional init command: +{cmd}.
30 This must be an Ex command that can be
31 followed by "|".
32 The rest of the command line is taken as the
33 file list. Thus any non-file arguments must
34 come before this.
35 You cannot edit stdin this way |--|.
36 The remote Vim is raised. If you don't want
37 this use >
38 vim --remote-send "<C-\><C-N>:n filename<CR>"
39< --remote-silent [+{cmd}] {file} ... *--remote-silent*
40 As above, but don't complain if there is no
41 server and the file is edited locally.
42 --remote-wait [+{cmd}] {file} ... *--remote-wait*
43 As --remote, but wait for files to complete
44 (unload) in remote Vim.
45 --remote-wait-silent [+{cmd}] {file} ... *--remote-wait-silent*
46 As --remote-wait, but don't complain if there
47 is no server.
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000048 *--remote-tab*
Bram Moolenaar038221b2006-03-11 21:32:59 +000049 --remote-tab Like --remote but open each file in a new
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000050 tabpage.
51 *--remote-tab-silent*
Bram Moolenaar038221b2006-03-11 21:32:59 +000052 --remote-tab-silent Like --remote-silent but open each file in a
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000053 new tabpage.
Bram Moolenaar038221b2006-03-11 21:32:59 +000054 *--remote-tab-wait*
55 --remote-tab-wait Like --remote-wait but open each file in a new
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000056 tabpage.
Bram Moolenaar038221b2006-03-11 21:32:59 +000057
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000058 *--remote-tab-wait-silent*
Bram Moolenaar038221b2006-03-11 21:32:59 +000059 --remote-tab-wait-silent Like --remote-wait-silent but open each file
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000060 in a new tabpage.
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 *--servername*
62 --servername {name} Become the server {name}. When used together
63 with one of the --remote commands: connect to
64 server {name} instead of the default (see
65 below).
66 *--remote-send*
67 --remote-send {keys} Send {keys} to server and exit.
68 *--remote-expr*
Bram Moolenaar362e1a32006-03-06 23:29:24 +000069 --remote-expr {expr} Evaluate {expr} in server and print the result
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000070 on stdout.
Bram Moolenaar071d4272004-06-13 20:20:40 +000071 *--serverlist*
72 --serverlist Output a list of server names.
73
74
75Examples ~
76
77Edit "file.txt" in an already running GVIM server: >
78 gvim --remote file.txt
79
80Edit "file.txt" in an already running server called FOOBAR: >
81 gvim --servername FOOBAR --remote file.txt
82
83Edit "file.txt" in server "FILES" if it exists, become server "FILES"
84otherwise: >
85 gvim --servername FILES --remote-silent file.txt
86
87This doesn't work, all arguments after --remote will be used as file names: >
88 gvim --remote --servername FOOBAR file.txt
89
90Edit file "+foo" in a remote server (note the use of "./" to avoid the special
91meaning of the leading plus): >
92 vim --remote ./+foo
93
94Tell the remote server "BLA" to write all files and exit: >
95 vim --servername BLA --remote-send '<C-\><C-N>:wqa<CR>'
96
97
98SERVER NAME
99
100By default Vim will try to register the name under which it was invoked (gvim,
101egvim ...). This can be overridden with the --servername argument. If the
102specified name is not available, a postfix is applied until a free name is
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000103encountered, i.e. "gvim1" for the second invocation of gvim on a particular
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104X-server. The resulting name is available in the servername builtin variable
105|v:servername|. The case of the server name is ignored, thus "gvim" and
106"GVIM" are considered equal.
107
108When Vim is invoked with --remote, --remote-wait or --remote-send it will try
109to locate the server name determined by the invocation name and --servername
110argument as described above. If an exact match is not available, the first
111server with the number postfix will be used. If a name with the number
112postfix is specified with the --servername argument, it must match exactly.
113
114If no server can be located and --remote or --remote-wait was used, Vim will
115start up according to the rest of the command line and do the editing by
116itself. This way it is not necessary to know whether gvim is already started
117when sending command to it.
118
119The --serverlist argument will cause Vim to print a list of registered command
120servers on the standard output (stdout) and exit.
121
122Win32 Note: Making the Vim server go to the foreground doesn't always work,
123because MS-Windows doesn't allow it. The client will move the server to the
124foreground when using the --remote or --remote-wait argument and the server
125name starts with "g".
126
127
128REMOTE EDITING
129
130The --remote argument will cause a |:drop| command to be constructed from the
131rest of the command line and sent as described above.
132The --remote-wait argument does the same thing and additionally sets up to
133wait for each of the files to have been edited. This uses the BufUnload
134event, thus as soon as a file has been unloaded, Vim assumes you are done
135editing it.
136Note that the --remote and --remote-wait arguments will consume the rest of
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000137the command line. I.e. all remaining arguments will be regarded as filenames.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138You can not put options there!
139
140
141FUNCTIONS
142 *E240* *E573*
143There are a number of Vim functions for scripting the command server. See
144the description in |eval.txt| or use CTRL-] on the function name to jump to
145the full explanation.
146
147 synopsis explanation ~
148 remote_expr( server, string, idvar) send expression
149 remote_send( server, string, idvar) send key sequence
150 serverlist() get a list of available servers
151 remote_peek( serverid, retvar) check for reply string
152 remote_read( serverid) read reply string
153 server2client( serverid, string) send reply string
154 remote_foreground( server) bring server to the front
155
156See also the explanation of |CTRL-\_CTRL-N|. Very useful as a leading key
157sequence.
158The {serverid} for server2client() can be obtained with expand("<client>")
159
160==============================================================================
1612. X11 specific items *x11-clientserver*
162 *E247* *E248* *E251* *E258* *E277*
163
164The communication between client and server goes through the X server. The
165display of the Vim server must be specified. The usual protection of the X
166server is used, you must be able to open a window on the X server for the
167communication to work. It is possible to communicate between different
168systems.
169
170By default, a GUI Vim will register a name on the X-server by which it can be
171addressed for subsequent execution of injected strings. Vim can also act as
172a client and send strings to other instances of Vim on the same X11 display.
173
174When an X11 GUI Vim (gvim) is started, it will try to register a send-server
175name on the 'VimRegistry' property on the root window.
176
177A non GUI Vim with access to the X11 display (|xterm-clipboard| enabled), can
178also act as a command server if a server name is explicitly given with the
179--servername argument.
180
181An empty --servername argument will cause the command server to be disabled.
182
183To send commands to a Vim server from another application, read the source
184file src/if_xcmdsrv.c, it contains some hints about the protocol used.
185
186==============================================================================
1873. Win32 specific items *w32-clientserver*
188
189Every Win32 Vim can work as a server, also in the console. You do not need a
190version compiled with OLE. Windows messages are used, this works on any
191version of MS-Windows. But only communication within one system is possible.
192
193Since MS-Windows messages are used, any other application should be able to
194communicate with a Vim server. An alternative is using the OLE functionality
195|ole-interface|.
196
197When using gvim, the --remote-wait only works properly this way: >
198
199 start /w gvim --remote-wait file.txt
200<
201 vim:tw=78:sw=4:ts=8:ft=help:norl: