aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-03-11 19:47:24 +0100
committerGitHub <noreply@github.com>2022-03-11 19:47:24 +0100
commit965f1fd6fd34ada255d79a6a6217a9fdfebd60ef (patch)
tree06e5500195b25df8039120db697521dd3595bc2b /runtime
parent76769b8a1f5b34f4b0cef389597cec2796ca91b7 (diff)
parent1201145b6893703fb351f51d9f2c742bd6946403 (diff)
downloadrneovim-965f1fd6fd34ada255d79a6a6217a9fdfebd60ef.tar.gz
rneovim-965f1fd6fd34ada255d79a6a6217a9fdfebd60ef.tar.bz2
rneovim-965f1fd6fd34ada255d79a6a6217a9fdfebd60ef.zip
Merge pull request #17439 from groves/1750
feat: restore --remote
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/remote.txt131
-rw-r--r--runtime/lua/vim/_editor.lua62
2 files changed, 193 insertions, 0 deletions
diff --git a/runtime/doc/remote.txt b/runtime/doc/remote.txt
new file mode 100644
index 0000000000..b8991be738
--- /dev/null
+++ b/runtime/doc/remote.txt
@@ -0,0 +1,131 @@
+*remote.txt* Nvim
+
+
+ VIM REFERENCE MANUAL by Bram Moolenaar
+
+
+Vim client-server communication *client-server*
+
+ Type |gO| to see the table of contents.
+
+==============================================================================
+1. Common functionality *clientserver*
+
+Nvim's |RPC| functionality allows clients to programmatically control Nvim. Nvim
+itself takes command-line arguments that cause it to become a client to another
+Nvim running as a server. These arguments match those provided by Vim's
+clientserver option.
+
+The following command line arguments are available:
+
+ argument meaning ~
+
+ --remote [+{cmd}] {file} ... *--remote*
+ Open the file list in a remote Vim. When
+ there is no Vim server, execute locally.
+ Vim allows one init command: +{cmd}.
+ This must be an Ex command that can be
+ followed by "|". It's not yet supported by
+ Nvim.
+ The rest of the command line is taken as the
+ file list. Thus any non-file arguments must
+ come before this.
+ You cannot edit stdin this way |--|.
+ The remote Vim is raised. If you don't want
+ this use >
+ nvim --remote-send "<C-\><C-N>:n filename<CR>"
+<
+ --remote-silent [+{cmd}] {file} ... *--remote-silent*
+ As above, but don't complain if there is no
+ server and the file is edited locally.
+ *--remote-tab*
+ --remote-tab Like --remote but open each file in a new
+ tabpage.
+ *--remote-tab-silent*
+ --remote-tab-silent Like --remote-silent but open each file in a
+ new tabpage.
+ *--remote-send*
+ --remote-send {keys} Send {keys} to server and exit. The {keys}
+ are not mapped. Special key names are
+ recognized, e.g., "<CR>" results in a CR
+ character.
+ *--remote-expr*
+ --remote-expr {expr} Evaluate {expr} in server and print the result
+ on stdout.
+ *--server*
+ --server {addr} Connect to the named pipe or socket at the
+ given address for executing remote commands.
+ See |--listen| for specifying an address when
+ starting a server.
+
+Examples ~
+
+Start an Nvim server listening on a named pipe at '~/.cache/nvim/server.pipe': >
+ nvim --listen ~/.cache/nvim/server.pipe
+
+Edit "file.txt" in an Nvim server listening at '~/.cache/nvim/server.pipe': >
+ nvim --server ~/.cache/nvim/server.pipe --remote file.txt
+
+This doesn't work, all arguments after --remote will be used as file names: >
+ nvim --remote --server ~/.cache/nvim/server.pipe file.txt
+
+Tell the remote server to write all files and exit: >
+ nvim --server ~/.cache/nvim/server.pipe --remote-send '<C-\><C-N>:wqa<CR>'
+
+
+REMOTE EDITING
+
+The --remote argument will cause a |:drop| command to be constructed from the
+rest of the command line and sent as described above.
+Note that the --remote and --remote-wait arguments will consume the rest of
+the command line. I.e. all remaining arguments will be regarded as filenames.
+You can not put options there!
+
+
+==============================================================================
+2. Missing functionality *E5600* *clientserver-missing*
+
+Vim supports additional functionality in clientserver that's not yet
+implemented in Nvim. In particular, none of the 'wait' variants are supported
+yet. The following command line arguments are not yet available:
+
+ argument meaning ~
+
+ --remote-wait [+{cmd}] {file} ... *--remote-wait*
+ Not yet supported by Nvim.
+ As --remote, but wait for files to complete
+ (unload) in remote Vim.
+ --remote-wait-silent [+{cmd}] {file} ... *--remote-wait-silent*
+ Not yet supported by Nvim.
+ As --remote-wait, but don't complain if there
+ is no server.
+ *--remote-tab-wait*
+ --remote-tab-wait Not yet supported by Nvim.
+ Like --remote-wait but open each file in a new
+ tabpage.
+ *--remote-tab-wait-silent*
+ --remote-tab-wait-silent Not yet supported by Nvim.
+ Like --remote-wait-silent but open each file
+ in a new tabpage.
+ *--servername*
+ --servername {name} Not yet supported by Nvim.
+ Become the server {name}. When used together
+ with one of the --remote commands: connect to
+ server {name} instead of the default (see
+ below). The name used will be uppercase.
+
+ *--serverlist*
+ --serverlist Not yet supported by Nvim.
+ Output a list of server names.
+
+
+
+
+SERVER NAME *client-server-name*
+
+By default Vim will try to register the name under which it was invoked (gvim,
+egvim ...). This can be overridden with the --servername argument. Nvim
+either listens on a named pipe or a socket and does not yet support this
+--servername functionality.
+
+ vim:tw=78:sw=4:ts=8:noet:ft=help:norl:
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 3136e36043..a0c60a7dcf 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -636,6 +636,68 @@ function vim.pretty_print(...)
return ...
end
+function vim._cs_remote(rcid, server_addr, connect_error, args)
+ local function connection_failure_errmsg(consequence)
+ local explanation
+ if server_addr == '' then
+ explanation = "No server specified with --server"
+ else
+ explanation = "Failed to connect to '" .. server_addr .. "'"
+ if connect_error ~= "" then
+ explanation = explanation .. ": " .. connect_error
+ end
+ end
+ return "E247: " .. explanation .. ". " .. consequence
+ end
+
+ local f_silent = false
+ local f_tab = false
+
+ local subcmd = string.sub(args[1],10)
+ if subcmd == 'tab' then
+ f_tab = true
+ elseif subcmd == 'silent' then
+ f_silent = true
+ elseif subcmd == 'wait' or subcmd == 'wait-silent' or subcmd == 'tab-wait' or subcmd == 'tab-wait-silent' then
+ return { errmsg = 'E5600: Wait commands not yet implemented in nvim' }
+ elseif subcmd == 'tab-silent' then
+ f_tab = true
+ f_silent = true
+ elseif subcmd == 'send' then
+ if rcid == 0 then
+ return { errmsg = connection_failure_errmsg('Send failed.') }
+ end
+ vim.fn.rpcrequest(rcid, 'nvim_input', args[2])
+ return { should_exit = true, tabbed = false }
+ elseif subcmd == 'expr' then
+ if rcid == 0 then
+ return { errmsg = connection_failure_errmsg('Send expression failed.') }
+ end
+ print(vim.fn.rpcrequest(rcid, 'nvim_eval', args[2]))
+ return { should_exit = true, tabbed = false }
+ elseif subcmd ~= '' then
+ return { errmsg='Unknown option argument: ' .. args[1] }
+ end
+
+ if rcid == 0 then
+ if not f_silent then
+ vim.notify(connection_failure_errmsg("Editing locally"), vim.log.levels.WARN)
+ end
+ else
+ local command = {}
+ if f_tab then table.insert(command, 'tab') end
+ table.insert(command, 'drop')
+ for i = 2, #args do
+ table.insert(command, vim.fn.fnameescape(args[i]))
+ end
+ vim.fn.rpcrequest(rcid, 'nvim_command', table.concat(command, ' '))
+ end
+
+ return {
+ should_exit = rcid ~= 0,
+ tabbed = f_tab,
+ }
+end
require('vim._meta')