Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore --remote (+clientserver) #1750

Closed
justinmk opened this issue Dec 28, 2014 · 53 comments · Fixed by #17439
Closed

restore --remote (+clientserver) #1750

justinmk opened this issue Dec 28, 2014 · 53 comments · Fixed by #17439
Assignees
Labels
api libnvim, Nvim RPC API compatibility compatibility with Vim or older Neovim
Milestone

Comments

@justinmk
Copy link
Member

AFAICT there is no reason we should not restore these Vim command line options:

   --remote <files>▸    Edit <files> in a Vim server if possible
   --remote-silent <files>  Same, don't complain if there is no server
   --remote-wait <files>  As --remote but wait for files to have been edited
   --remote-wait-silent <files>  Same, don't complain if there is no server
   --remote-tab[-wait][-silent] <files>  As --remote but use tab page per file
   --remote-send <keys>▸Send <keys> to a Vim server and exit
   --remote-expr <expr>▸Evaluate <expr> in a Vim server and print result 

What is the equivalent of these options in the current state of Neovim? cc @tarruda

@justinmk justinmk added api libnvim, Nvim RPC API compatibility compatibility with Vim or older Neovim labels Dec 28, 2014
@xu-cheng
Copy link
Contributor

👍 I really need this for synctex.

@tarruda
Copy link
Member

tarruda commented Dec 29, 2014

What is the equivalent of these options in the current state of Neovim? cc @tarruda

Any of vim remote-* commands can be easily emulated via msgpack-rpc, here's a quick and dirty python implementation:

#!/usr/bin/env python
import click, re, sys
from neovim import attach


IP_ADDR = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\:\d{1,5})?$')


@click.command(context_settings=dict(allow_extra_args=True))
@click.option('--address')
@click.option('--send', default=None)
@click.option('--expr', default=None)
@click.option('--tab/--no-tab', default=False)
@click.option('--silent/--no-silent', default=False)
@click.pass_context
def main(ctx, address, send, expr, tab, silent):
    if IP_ADDR.match(address):
        args = ('tcp',)
        kwargs = {'address': address}
    else:
        args = ('socket',)
        kwargs = {'path': address}
    try:
        nvim = attach(*args, **kwargs)
    except Exception as e:
        if not silent:
            print >> sys.stderr, e.message
        sys.exit(1)

    if send:
        nvim.input(send)
    elif expr:
        print nvim.eval(expr)
    else:
        files = ctx.args
        if not files:
            print >> sys.stderr, 'Need at least one file to edit'
            sys.exit(1)
        cmd = 'tabedit' if tab else 'edit'
        for f in files:
            nvim.command('{0} {1}'.format(cmd, f))


if __name__ == '__main__':
    main()

The question is, do we need to bundle this functionality in the nvim executable? IMO it would be better to have a general purpose shell utility and distribute it with nvim.

@justinmk
Copy link
Member Author

With something like #1446 we wouldn't need python. I would say it should be bundled

@aktau
Copy link
Member

aktau commented Dec 31, 2014

With something like #1446 we wouldn't need python. I would say it should be bundled

Yea, ideally it should just work without fussing and (as has been recently shown by @justinmk) getting python to work is not always fuss-free. So a VimL implementation of this functionality would, in my mind, show the true power of nvim.

@jalvesaq
Copy link
Contributor

jalvesaq commented Jun 1, 2015

Just an idea: Perhaps Neovim could ship with a small application written in C called nvimclient that would do only one thing: get the environment variable NVIM_LISTEN_ADDRESS and send a message to that address. Then, it would be easy to implement SyncTeX backward with PDF viewers like Zathura and Sumatra which accept a command line argument to setup the backward search. If the pdf viewers are started by nvim, they will inherit its environment variables. The nvimclient could also accept the --servername argument for compatibility with Vim plugins that use the 'clientserver' feature.

@justinmk
Copy link
Member Author

justinmk commented Jun 2, 2015

Why a separate program?

@jalvesaq
Copy link
Contributor

jalvesaq commented Jun 2, 2015

The main reason to have a separate program is because it would be quicker to launch, but I am not sure if this is necessary since nvim is already lightweight. Another reason is that when nvim finds the environment variable NVIM_LISTEN_ADDRESS it listens on the address while the nvimclient would write to it. But this is not a good reason too because the arguments --remote-expr etc will turn nvim into a client. One third reason is that the command line to call nvimclient would be simpler than calling nvim. For example, it could be

nvimclient 'call MyFunction("text here", 0)'

instead of

nvim --servername /tmp/nvimCg4gH/0 --remote-expr 'MyFunction("text here", 0)'

But, at the end, I am sure that any implementation will be good and plugin developers will adapt to whatever decision Neovim developers make.

@tarruda
Copy link
Member

tarruda commented Jun 2, 2015

The main reason to have a separate program is because it would be quicker to launch, but I am not sure if this is necessary since nvim is already lightweight.

@jalvesaq as long as we only run the code necessary to connect and send the message(no need to source vimrc or any other scripts), the startup would already be fast since it's very likely that the code is already cached by the operating system.

Another reason is that when nvim finds the environment variable NVIM_LISTEN_ADDRESS it listens on the address while the nvimclient would write to it.

We need to change that, now that we have a serverlisten function, it would be better to only listen on a socket when explicitly started by the user or a plugin.

Honestly, I don't think we need to reimplement the --remote-* flags from vim, there's no need to maintain compatibility with command line options. With the changes introduced by @splinterofchaos in #1446, rpcrequest/rpcnotify can already control remote nvim instances in any way imaginable. We just need a rpcconnect function to connect to an already running instance(rpcstart will spawn a new instance).

With a vimscript command library wrapping rpcrequest/rpcconnect, sending a command to another nvim would be as simple:

nvim -u NONE +'RemoteSend /path/to/socket command'

@jalvesaq
Copy link
Contributor

jalvesaq commented Jun 2, 2015

It's good to know that only rpcconnect is missing!

@Moelf
Copy link
Sponsor

Moelf commented Aug 15, 2015

As you guys are talking about, is there a way to make neovim + Skim backward search working?

@justinmk
Copy link
Member Author

I don't know what Skim is.

@jalvesaq
Copy link
Contributor

Skim is a PDF viewer (Mac OS X) with SyncTeX support. For those who don't know, SyncTeX is a system of synchronization between a LaTeX text editor (which might be Vim or Neovim) and the PDF viewer. We can both click in the PDF to jump to the corresponding line in the text editor and issue a command in the text editor to jump to the corresponding place in the PDF. That is, we need a way of sending a message from the PDF editor to Neovim. In Vim, the 'clientserver' is used for SyncTeX.

I implemented SyncTeX support for Rnoweb (LaTeX + R) files in Neovim (Nvim-R), but in order to do this, I created a C application that runs a TCP server (run as a Neovim job) and another C application that I called nvimrclient which sends messages to the server. The PDF viewer must be configured to run the nvimrclient.

@justinmk
Copy link
Member Author

I created a C application that runs a TCP server (run as a Neovim job) and another C application that I called nvimrclient which sends messages to the server.

A very urgent goal for us is to make nvim serve this purpose out of the box, i.e., it should be a client of itself. #3119

The legacy --remote feature would be implemented as a special case of this general capability.

@justinmk justinmk added this to the 0.2 milestone Aug 15, 2015
@tarruda tarruda self-assigned this Nov 5, 2015
@lervag
Copy link
Contributor

lervag commented Nov 7, 2015

Agreed, I also would very much like this feature in neovim. I'm developing vimtex, and I am using callbacks with the following syntax in vim:

vim --servername NAME --remote-expr "function-name()"

I both know and understand that I can utilize external scripts through python and ruby (and I guess other languages), but I think the "old" method is very convenient for my particular need.

I am currently working on neovim support, see #262, and if the legacy feature was added to neovim, then the changes required in vimtex would be minimal.

@mhinz
Copy link
Member

mhinz commented Dec 4, 2015

As long as there's no other solution, here a wrapper script that handles --remote and friends: https://github.com/mhinz/neovim-remote

@justinmk
Copy link
Member Author

justinmk commented Dec 4, 2015

Awesome. That makes it straightforward for someone to use as a reference for implementing in C.

@lervag
Copy link
Contributor

lervag commented Dec 6, 2015

Thanks, @mhinz!

@mkoskar
Copy link

mkoskar commented Feb 16, 2016

Doing

nvr --servername $TMPDIR/nvim --remote-tab /tmp

or

nvr --servername $TMPDIR/nvim -c 'tabedit /tmp'

given that /tmp is real directory tab is not opened. I can see the buffer listed though. I know that directories are treated specially, and in this case I've disabled netrw but just for sake of consistency it should behave the same as when doing :tabedit /tmp from inside nvim when actually new tab is created. Could this be related to the fact that autocommands are not triggered (as I've learned from nvim-remote README)?

@lluixhi
Copy link

lluixhi commented Apr 21, 2016

What's the status on this bug exactly? Are we going to stick with the status quo or bundle a client program for compatiblity with vim?

I'm curious because I'm considering packaging https://github.com/mhinz/neovim-remote, and if it's only a temporary solution, there's not much point.

@justinmk
Copy link
Member Author

Are we going to stick with the status quo or bundle a client program for compatiblity with vim?

Neither. https://github.com/mhinz/neovim-remote is a temporary solution.

@lervag
Copy link
Contributor

lervag commented Apr 22, 2016

I'm curious: Is there any work on this yet? I am very much looking forward to neovim getting support for the --remote commands again!

@nadya-p
Copy link

nadya-p commented Nov 14, 2018

neovim-remote plugin doesn't work on windows, so #8326 would be very helpful.

In particular, this would enable a neovim-based LaTeX workflow using vimtex and including its backward-search functionality (ability to jump from a line in pdf file back to the corresponding LaTeX source line in neovim).

@iamkarlson
Copy link

@nadya-p this would enable a lot of stuff. including but not limited to the case you sounded and also using neovim as git editor

@iurobpn

This comment has been minimized.

@KillTheMule

This comment has been minimized.

@bfredl
Copy link
Member

bfredl commented Dec 13, 2018

@iurobpn This is actively worked on in #8326

@iurobpn

This comment has been minimized.

@pierreganty

This comment has been minimized.

@yashamon

This comment has been minimized.

@iurobpn
Copy link

iurobpn commented Dec 14, 2018

If anyone run into the same problem, this vimura script solved this for me. There are more steps in the link, but I just used the vimura to substitute my configuration of the zathura 'backward search'.

@yashamon , I used the nvr.

justinmk pushed a commit that referenced this issue Jul 8, 2021
There are plans to support the --remote-xx stuff (or something like it): #1750 #8326
But we don't need this doc meanwhile.
@clason clason modified the milestones: 0.6, 0.7 Nov 30, 2021
@zeertzjq zeertzjq modified the milestones: 0.8, 0.7 Mar 12, 2022
@neovim neovim deleted a comment from rvega May 4, 2022
@neovim neovim deleted a comment from Moelf May 4, 2022
@neovim neovim deleted a comment from ktonga May 4, 2022
@neovim neovim deleted a comment from lervag May 4, 2022
@neovim neovim deleted a comment from cewood May 4, 2022
@neovim neovim deleted a comment from sisrfeng May 4, 2022
@neovim neovim locked as resolved and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api libnvim, Nvim RPC API compatibility compatibility with Vim or older Neovim
Projects
None yet
Development

Successfully merging a pull request may close this issue.