12

in vim I can do vim --servername foo and vim --servername foo --remote-silent bar.txt to open files in one instance of vim from several terminal windows (via tmux or whatever). How is the same thing achieved in NeoVim?

8

As far as I know vim has this feature because the GUI vim (gvim) uses the graphical X server. I am aware that non GUI Vim can also use the --servername argument but only when X11 is running and also by accessing to it. On the other hand, neovim has no graphical support; for that reason, I don't think that the --servername option can work (unless the option would have been fully rewritten in another way) since I would find strange to have a console program accessing the X11 server only for that purpose.

  • At first I thought this answer was wrong, since IPC without X is not just possible, but also very common (eg. sockets). But :help x11-clientserver seems to confirm it: "The communication between client and server goes through the X server. [..] A non GUI Vim with access to the X11 display (|xterm-clipboard| enabled), can also act as a command server if a server name is explicitly given" ... – Martin Tournoij Nov 14 '15 at 23:03
5

Neovim remote is a python script for controlling neovim processes. It has the vim style --servername and --remote options. This is what I use now for my multiple-terminal work environment.

  • It worth mentioning that this plugin does not work for Windows platform. – jdhao Mar 26 at 12:08
2

As mentioned, all of the clientserver features were removed in Neovim. This is because they use the X11 shared memory and Neovim removed X11 support.

However, if I use :help --servername in Neovim I end up in the documentation for the serverstart() function:

serverstart([{address}])                                serverstart()
                Opens a named pipe or TCP socket at {address} for clients to
                connect to and returns {address}. If no address is given, it
                is equivalent to:
                        :call serverstart(tempname())
                $NVIM_LISTEN_ADDRESS is set to {address} if not already set.
                                                        --servername
                The Vim command-line option --servername can be imitated:
                        nvim --cmd "let g:server_addr = serverstart('foo')"

This will make a socket in /tmp/; see :echo v:servername for the path. It's probably more useful to use a more deterministic address (e.g. serverstart('/tmp/nvim-remote'); although you'll probably want to wrap this in a function, as it won't append a number like Vim's --serverstart does if this already exists).

You can send commands with the RPC API. As far as I can find there is no way to send commands to this with just Neovim (meh). You'll need to install one of the API clients. For example with the reference Python API client (which is also what Neovim remote uses):

import neovim
nvim = neovim.attach('socket', path='/tmp/nvim-remote')
try:
    nvim.command(':e foo')
finally:
    nvim.quit()

You can probably send the same bytes with a echo ... >> /tmp/nvim-remove shell command, but the RPC API uses a somewhat non-trivial non-text protocol ("MessagePack RPC") and figuring out which bytes to send exactly was a bit too much effort for this post ;-)

See :help rpc for the full details on Neovim's RPC API.


N.B. :help remote.txt as well as many other help items (such as help server2client() and many more) still exists in Neovim, but none of that works. It looks like whoever removed this feature did a pretty sloppy job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.