Package: nvim-remote
nvim remoteforked from https://github.com/mhinz/neovim-remoteThis package provides an executable callednvrwhich solves these cases:Controlling nvim processes from the shell. E.g. opening files in another
terminal window.Opening files from within:terminalwithout starting a nested nvim process.InstallationTheoryFirst stepsTypical use casesDemosFAQInstallationpip3installnvim-remote

pipxinstallnvim-remoteTheorynvimalways starts a server. Get its address with:echo v:servername. Or
specify an address at startup:nvim --listen /tmp/nvimsocket.nvr(the client) will use any address given to it via--servername,$NVIM_LISTEN_ADDRESS(obsolete in nvim but still supported innvr), or
defaults to/tmp/nvimsocket.If the targeted address does not exist,nvrstarts a new process by running
"nvim". You can change the command by setting$NVR_CMD.(This requires
forking, so it won't work on Windows.)First stepsStart a nvim process (which acts as a server) in one shell:nvim--listen/tmp/nvimsocketAnd do this in another shell:# nvr uses /tmp/nvimsocket by default, so we're good.# Open two files:nvr--remotefile1file2# Send keys to the current buffer:nvr--remote-send'iabc<esc>'# Enter insert mode, insert 'abc', and go back to normal mode again.# Evaluate any VimL expression, e.g. get the current buffer:nvr--remote-expr'bufname("")'README.mdclick here to see all nvr options$nvr-h
usage:nvr[arguments]RemotecontrolNeovimprocesses.

Ifnoprocessisfound,anewonewillbestarted.$nvr--remote-send'iabc<cr><esc>'$nvr--remote-expr'map([1,2,3], "v:val + 1")'Anyargumentsnotconsumedbyoptionswillbefedto--remote-silent:$nvr--remote-silentfile1file2$nvrfile1file2

All--remoteoptionstakeoptionalcommands.
Exception:--remote-expr,--remote-send.$nvr+10file$nvr+'echomsg "foo" | echomsg "bar"'file$nvr--remote-tab-wait+'set bufhidden=delete'file

Openfilesinanewwindowfromaterminalbuffer:$nvr-ccsplitfile1file2

Usenvrfromgittoeditcommitmessages:$gitconfig--globalcore.editor'nvr --remote-wait-silent'optionalarguments:-h,--helpshowthishelpmessageandexit--remote[<file>[<file>...]]Use:edittoopenfiles.Ifnoprocessisfound,throwanerrorandstartanewone.--remote-wait[<file>[<file>...]]Like--remote,butblockuntilallbuffersopenedbythisoptiongetdeletedortheprocessexits.--remote-silent[<file>[<file>...]]Like--remote,butthrownoerrorifnoprocessisfound.--remote-wait-silent[<file>[<file>...]]Combines--remote-waitand--remote-silent.--remote-tab[<file>[<file>...]]Like--remote,butuse:tabedit.--remote-tab-wait[<file>[<file>...]]Like--remote-wait,butuse:tabedit.--remote-tab-silent[<file>[<file>...]]Like--remote-silent,butuse:tabedit.--remote-tab-wait-silent[<file>[<file>...]]Like--remote-wait-silent,butuse:tabedit.--remote-send<keys>Sendkeypresses.--remote-expr<expr>Evaluateexpressionandprintresultinshell.--servername<addr>Settheaddresstobeused.Thisoverridesthedefault"/tmp/nvimsocket"and$NVIM_LISTEN_ADDRESS.--serverlistPrinttheTCPv4andUnixdomainsocketaddressesofallnvimprocesses.-cc<cmd>Executeacommandbeforeeveryotheroption.-c<cmd>Executeacommandaftereveryotheroption.-dDiffmode.Use:diffthisonalltobeopenedbuffers.-lChangetopreviouswindowvia":wincmd p".-o<file>[<file>...]Openfilesvia":split".-O<file>[<file>...]Openfilesvia":vsplit".-p<file>[<file>...]Openfilesvia":tabedit".-q<errorfile>Readerrorfileintoquickfixlistanddisplayfirsterror.-sSilence"no server found"message.-t<tag>Jumptofileandpositionofgiventag.--nostartIfnoprocessisfound,donotstartanewone.--versionShowthenvrversion.

Development:https://github.com/mhinz/neovim-remote

Happyhacking!Typical use casesOpen files from within:terminalwithout starting a nested nvim process.Easy-peasy! Justnvr file.This works without any prior setup, because$NVIMis always set for all
children of the nvim process, including:terminal, andnvrwill default
to that address.I often work with two windows next to each other. If one contains the
terminal, I can usenvr -l footo open the file in the other window.Open files always in the same nvim process no matter which terminal you're in.Justnvr -sstarts a new nvim process with the server address set to/tmp/nvimsocket.Now, no matter which terminal you are in,nvr filewill always work on
that nvim process. That is akin toemacsclientfrom Emacs.Use nvr in plugins.Some plugins rely on the--remotefamily of options from Vim. Nvim had to
remove those when they switched to outsource a lot of manual code to libuv.
These options areplanned to be added back, though.In these cases nvr can be used as a drop-in replacement. E.g.vimtexcan be configured to use nvr to
jump to a certain file and line:read.Use nvr as git editor.Imagine Neovim is set as your default editor via$VISUALor$EDITOR.Runninggit commitin a regular shell starts a nvim process. But in a
terminal buffer (:terminal), a new nvim process starts as well. Now you
have one nvim nested within another.If you do not want this, put this in your vimrc:ifhas('nvim')let$GIT_EDITOR='nvr -cc split --remote-wait'endifThat way, you get a new window for inserting the commit message instead of a
nested nvim process. But git still waits for nvr to finish, so make sure to
delete the buffer after saving the commit message::w | bd.If you don't like using:w | bdand prefer the good old:wq(or:x),
put the following in your vimrc:autocmdFileTypegitcommit,gitrebase,gitconfigsetbufhidden=deleteTo use nvr from a regular shell as well:git config --global core.editor 'nvr --remote-wait-silent'Use nvr as git mergetool.If you want to use nvr forgit difftoolandgit mergetool, put this in
your gitconfig:[diff]
    tool = nvr
[difftool "nvr"]
    cmd = nvr -s -d $LOCAL $REMOTE
[merge]
    tool = nvr
[mergetool "nvr"]
    cmd = nvr -s -d $LOCAL $BASE $REMOTE $MERGED -c 'wincmd J | wincmd ='nvr -dis a shortcut fornvr -d -Oand acts likevim -d, thus it uses:vsplitto open the buffers. If you want them to be opened via:splitinstead, usenvr -d -o.When used as mergetool and all four buffers got opened, the cursor is in the
window containing the $MERGED buffer. We move it to the bottom via:wincmd Jand then equalize the size of all windows via:wincmd =.Use nvr for scripting.You might draw some inspiration fromthis Reddit
thread.Demos(Click on the GIFs to watch them full-size.)Using nvr from another shell:Using nvr from within:terminal:FAQHow to open directories?:e /tmpopens a directory view via netrw. Netrw works by hooking into certain
events,BufEnterin this case (see:au FileExplorerfor all of them).Unfortunately Neovim's API doesn't trigger any autocmds on its own, so simplynvr /tmpwon't work. Meanwhile you can work around it like this:nvr /tmp -c 'doautocmd BufEnter'Reading from stdin?Yes! E.g.echo "foo\nbar" | nvr -o -andcat file | nvr --remote -work just
as you would expect them to work.Exit code?If you use arecent enough
Neovim, nvr will use the same exit code as the linked nvim.E.g.nvr --remote-wait <file>and then:cquitin the linked nvim will make
nvr return with 1.How to send a message to all waiting clients?If you open a buffer with any of thewaitoptions, that buffer will get a
variableb:nvr. The variable contains a list of channels wheres each
channel is a waiting nvr client.Currently nvr only understands theExitmessage. You could use it to
disconnect all waiting nvr clients at once:command!DisconnectClients
    \ifexists('b:nvr')\|forclientinb:nvr
    \|silent!callrpcnotify(client,'Exit',1)\|endfor\|endifCan I have auto-completion for bash/fish?If you want basic auto-completion for bash, you can sourcethis
scriptin your .bashrc.This also completes server names with the--servernameoption.If you want auto-completion for fish, you can addthis
fileto your fish completions dir.