neovim icon indicating copy to clipboard operation
neovim copied to clipboard

Remote open if swap exists

Open goulf-3m opened this issue 10 months ago • 3 comments

Problem

In Julia, it is possible to open and locate a file in the error stack trace. However, using this frequently is slow (language server initialization...). It will be much faster if the Julia script is opened in a long-running vim instance; and locating an error just reuses the instance.

More generally, it will be convenient if users are allowed to choose whether to use a new vim instance or to reuse an existing vim instance (that opened the target file).

Expected behavior

Currently, when opening a file that is already opened, nvim displays:

...
        process ID: 769509 (STILL RUNNING)
...
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

It knows which process (thus the server address) opened the file. So it is possible to remote open (and locate lines) this file. I expect a prompt like:

[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort, O(p)en remote:

So that when debugging Julia, I can simply choose (p), without any special configurations.

goulf-3m avatar Mar 26 '24 10:03 goulf-3m

The swap dialog is a particular case, and not really relevant to the actual request here, which is to be able to "open (or share?) a buffer from a peer Nvim"?

What exactly do you expect to happen with Open remote is selected? Will the current Nvim open a buffer that is "owned" by the remote peer?

In a GUI, the "cheap" way to do this (which vscode also does) is to focus the remote instance.

Proposal

  1. swapfiles should also store the Nvim server address, not only the PID
    • Not technically necessary, because the (default) Nvim listen address includes the PID in its name: https://github.com/neovim/neovim/blob/0c0be09eab66975e62c67522620fee10f82663d2/src/nvim/msgpack_rpc/server.c#L99-L100
  2. provide a command that spawns a new UI connected to a server address: :gui <address>
    • if the server is on the same machine, optionally tries to focus (bring to foreground) the existing UI instead of spawning a new UI?

justinmk avatar Mar 27 '24 15:03 justinmk

The swap dialog is a particular case, and not really relevant to the actual request here, which is to be able to "open (or share?) a buffer from a peer Nvim"?

In my opinion, swap file, swap dialog, and buffer share are quite relevant. In certain (even most of the) situations, the only correct choice when the swap file already exists is to connect to a peer. So a builtin shortcut would be quite helpful; or otherwise I have to quite and manually find the peer instance.

What exactly do you expect to happen with Open remote is selected? Will the current Nvim open a buffer that is "owned" by the remote peer?

I expect something similar to the Switch to Tab feature in Firefox: when the URL has been opened in an existing tab, I can choose to open a new tab or jump to the existing tab.

I noticed there is a macros/editexisting.vim script for this. But: It does not work in nvim out of the box and needs tweaking.

goulf-3m avatar Mar 30 '24 04:03 goulf-3m

See: flatten.nvim for remote opening needs

IndianBoy42 avatar May 09 '24 10:05 IndianBoy42

Reading above it looks like two distinct options would be of use:

  • Open File in Existing nvim instance
    • in TUI environment this could be complicated and not quite intuitive, but definitely worth exploring for GUI. In other words having some mechanism to notify running instances would be good. VSCode uses -r for this so it could be interesting preserving the same nomenclature for easy switch between editors.
  • Open new "view" instance using already running instance as a server.

also, personally, I have not come across an instance where I'd want to open file already opened by another nvim instance outside of the above two... but perhaps leaving read-only option as another alternative is needed for compatibility purposes.

droopy4096 avatar Dec 09 '24 22:12 droopy4096