12

I want to open new files from the command line on Windows in a single nvim-qt instance that is already open.

I know the existence of the --server option, but how do I know the IP or the socket name or path of the running instance?

el_technic0
  • 553
  • 6
  • 14
  • 2
    Sorry now i see, nvim has removed the `--servername` attribute. you can get the server socket with `:echo v:servername` more about that here: https://vi.stackexchange.com/questions/5348/how-can-i-use-servername-and-remote-in-neovim. There also seems to be a plugin: https://github.com/mhinz/neovim-remote. – Doktor OSwaldo Aug 23 '17 at 10:46
  • Wow! That's exactly what I failed to find. Thank you! – el_technic0 Aug 23 '17 at 11:06
  • Ok so after my initial excitement, I can't still open a file in an existing instance. So far I'm able to open a new nvim-qt window with `nvim-qt.exe --server "127.0.0.1:7777"` or any other address that is in use (`:echo serverlist()`). If I add a file to edit to the command though, it no longer opens up a window or anything. – el_technic0 Aug 23 '17 at 12:33
  • it woukd be `--remote` not `--server` but this both seems to be removed (i do not use neovim, but vim itself) there is an API for the usecase you have, but calling it seems non trivial. I would go for the plugin if possible, and if not try to comment under carpetsmoker's post. Maybe he knows more. Unfortunaly i can't help you any further without neovim and without windows. – Doktor OSwaldo Aug 23 '17 at 13:28

1 Answers1

2

As el_technic0 said, the neovim-remote utility is the easiest way to get remote file opening to work. I even added an alias to it in my .bashrc file (alongside the listen address definition) for easier invocation:

export NVIM_LISTEN_ADDRESS=/tmp/nvimsocket
alias vim='nvr --remote'

This way the first call will start a new neovim instance, and subsequent calls will be forwarded to that instance.

You may also want to add the set hidden option to your init.vim configuration file, otherwise subsequent calls may fail if the current buffer contains unsaved changes.

xperroni
  • 2,606
  • 1
  • 23
  • 29
  • Ok, but the question states "I want to open new files from the command line *on Windows*" and this thing doesn't work on WIndows. – ashrasmun Aug 12 '21 at 10:16
  • Apparently it worked well enough for the question owner though, since he accepted my answer. – xperroni Aug 13 '21 at 13:09