From 842a22a4797d490fdadcfd83d6b51475afe78f93 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 4 May 2022 12:16:14 +0200 Subject: [PATCH] Doc: $NVIM_LISTEN_ADDRESS is obsolete in nvim The server should be started with `nvim --listen /tmp/nvimsocket` or just `nvr`. When used as client, nvr still supports $NVIM_LISTEN_ADDRESS for backward compatibility. --- README.md | 23 ++++++++++++----------- nvr/nvr.py | 32 ++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 13d67ee..35d778e 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,12 @@ If you encounter any issues, e.g. permission denied errors or you can't find the ## Theory -Nvim always starts a server. Get its address via `:echo $NVIM_LISTEN_ADDRESS` or -`:echo v:servername`. Or specify an address at startup: -`NVIM_LISTEN_ADDRESS=/tmp/nvimsocket nvim`. +**Nvim** always starts a server. Get its address with `:echo v:servername`. Or +specify an address at startup: `nvim --listen /tmp/nvimsocket`. -**nvr** will use `$NVIM_LISTEN_ADDRESS` or any address given to it via -`--servername`. +**nvr** (the client) will use any address given to it via `--servername`, +`$NVIM_LISTEN_ADDRESS` (obsolete in nvim but still supported in nvr), or +defaults to `/tmp/nvimsocket`. If the targeted address does not exist, **nvr** starts a new process by running "nvim". You can change the command by setting `$NVR_CMD`. _(This requires @@ -46,7 +46,7 @@ forking, so it won't work on Windows.)_ Start a nvim process (which acts as a server) in one shell: - NVIM_LISTEN_ADDRESS=/tmp/nvimsocket nvim + nvim --listen /tmp/nvimsocket And do this in another shell: @@ -155,18 +155,19 @@ Happy hacking! Easy-peasy! Just `nvr file`. - This works without any prior setup, because `$NVIM_LISTEN_ADDRESS` is always - set within Nvim. And `nvr` will default to that address. + This works without any prior setup, because `$NVIM` is always set for all + children of the nvim process, including `:terminal`, and `nvr` will default + to that address. I often work with two windows next to each other. If one contains the terminal, I can use `nvr -l foo` to open the file in the other window. - **Open files always in the same nvim process no matter which terminal you're in.** - If you just run `nvr -s`, a new nvim process will start and set its address - to `/tmp/nvimsocket` automatically. + Just `nvr -s` starts a new nvim process with the server address set to + `/tmp/nvimsocket`. - Now, no matter in which terminal you are, `nvr file` will always work on + Now, no matter which terminal you are in, `nvr file` will always work on that nvim process. That is akin to `emacsclient` from Emacs. - **Use nvr in plugins.** diff --git a/nvr/nvr.py b/nvr/nvr.py index ae55b2f..261d6bc 100644 --- a/nvr/nvr.py +++ b/nvr/nvr.py @@ -309,36 +309,40 @@ def parse_args(argv): def show_message(address): - print(textwrap.dedent(''' - [!] Can't connect to: {} + print(textwrap.dedent(f''' + [!] Can't connect to: {address} The server (nvim) and client (nvr) have to use the same address. Server: - Expose $NVIM_LISTEN_ADDRESS to the environment before - starting nvim: + Specify the server address when starting nvim: - $ NVIM_LISTEN_ADDRESS={} nvim + $ nvim --listen {address} Use `:echo v:servername` to verify the address. - Security: When using Unix domain sockets on a multi-user system, - the socket should have proper permissions so that it is only - accessible by your user. + Alternatively, run nvr without arguments. It defaults to + starting a new nvim process with the server name set to + "/tmp/nvimsocket". + + Security: When using an Unix domain socket, that socket should + have proper permissions so that it is only accessible by your + user. Client: - Expose $NVIM_LISTEN_ADDRESS to the environment before - using nvr or use its --servername option. If neither - is given, nvr assumes \"/tmp/nvimsocket\". + Expose $NVIM_LISTEN_ADDRESS (obsolete in nvim but still + supported by nvr) to the environment before using nvr or use + its --servername option. If neither is given, nvr assumes + \"/tmp/nvimsocket\". - $ NVIM_LISTEN_ADDRESS={} nvr file1 file2 - $ nvr --servername {} file1 file2 + $ NVIM_LISTEN_ADDRESS={address} nvr file1 file2 + $ nvr --servername {address} file1 file2 $ nvr --servername 127.0.0.1:6789 file1 file2 Use -s to suppress this message. - '''.format(address, address, address, address))) + ''')) def split_cmds_from_files(args):