remote.txt 8.4 KB

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