neovide icon indicating copy to clipboard operation
neovide copied to clipboard

FR: CLI option to open new files in the existing instance of Neovide instead of creating a new one

Open chrisgrieser opened this issue 3 years ago • 22 comments
trafficstars

Is your feature request related to a problem? Please describe. When Neovide is already open, and I use neovide (the CLI) to open another file, another instance of Neovide is opened instead of opening neovide in a new buffer in the already existing instance.

This is very impractical, since I often accidentally end up with several neovide instances, which cannot be dealt with properly via the OS (all have the same icon and same app name for app switchers), and also I cannot switch between them with things like :buffer.

Describe the solution you'd like a CLI option to open new files in the existing instance of Neovide instead of creating a new one

Describe alternatives you've considered Only opening the first file via neovide and all other files from inside neovide? That is quite cumbersome to do though.

As @bboles outlined in a different issue, if the Neovide.app would use the "open with" feature on mac properly, one could open files with the app and it would open in the same instance. If that is going to be implemented, open -a "Neovide" {filename} could be a workaround for this.

chrisgrieser avatar Oct 04 '22 13:10 chrisgrieser

Breaking the current standard and messing up people's workflows is the easiest way to saturate this issues page with an angry mob. Instead of changing the default it would be better to expose an argument which does that, but otherwise I agree this would be a cool feature.

avalonv avatar Oct 05 '22 01:10 avalonv

As it is, Neovide does not seem to be able to run multiple windows in one instance, so doing this would definitely break expected behaviour?

tstm avatar Oct 13 '22 11:10 tstm

Breaking the current standard and messing up people's workflows is the easiest way to saturate this issues page with an angry mob. Instead of changing the default it would be better to expose an argument which does that, but otherwise I agree this would be a cool feature.

Yes, an option was what I meant. Edited for clarity.

chrisgrieser avatar Oct 14 '22 12:10 chrisgrieser

+1 To this. I'd be OK with a special CLI command for this, a la VSCode or VimR, or a flag. I'd expect it to open a new buffer, not a new macOS window.

kemiller avatar Nov 11 '22 18:11 kemiller

yep, would be grate feature to have.

Solution in this case can be pretty trivial, since neovide relay on a nvim server any way we just need to define static listener and then send --remote command to it. In my case implementation was next. I've created script in /usr/local/bin/v and use my own socket.

#!/bin/sh

NVIM_SOCKET=/tmp/neovide.socket
if [ ! -S $NVIM_SOCKET ]; then
    neovide --noidle  -- --listen $NVIM_SOCKET $@
else
    nvim --server $NVIM_SOCKET --remote $@
fi

shemerey avatar Feb 08 '23 20:02 shemerey

+1 To this. I'd be OK with a special CLI command for this, a la VSCode or VimR, or a flag. I'd expect it to open a new buffer, not a new macOS window.

I strongly disagree with this. If you want a new buffer you should just open a new buffer in the current window.

I actually need an entirely different window so it can go on other monitors, or so I can move projects around independently, but they should spawn out of the same icon so you dont get this:

image

I think the flag should enable functionality exactly like all the other Vim GUI's like MacVim, VimR, etc, where it opens in a new window spawned under the same icon.

9mm avatar Aug 13 '23 13:08 9mm

As a sidenote, I just HAD to do this;

➜  ~ n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n; n; n; n; n;n;n;

When they open, they create a literal wave 🌊

image

9mm avatar Aug 13 '23 13:08 9mm

I think it would be nice to have an option that makes it possible to reuse (open) the existing neovide window if you call neovide to open in the CWD that already was opened inside other neovide window.

This feature makes it possible to comfortably use Neovide as part of Tmux workflow with sessions and its windows. So you open Neovide window in CWD that you want and continue to use terminal session. Then switch to the existing Neovide window easily calling Neovide again.

For example, for me missing this kind of feature is a dealbreaker to use Neovide regularly.

mambusskruj avatar Sep 05 '23 11:09 mambusskruj

I think it would be nice to have an option that makes it possible to reuse (open) the existing neovide window if you call neovide to open in the CWD that already was opened inside other neovide window.

This feature makes it possible to comfortably use Neovide as part of Tmux workflow with sessions and its windows. So you open Neovide window in CWD that you want and continue to use terminal session. Then switch to the existing Neovide window easily calling Neovide again.

For example, for me missing this kind of feature is a dealbreaker to use Neovide regularly.

Agree

idelice avatar Feb 18 '24 09:02 idelice

Due to the PR #2395, the Neovide.app now can open files correctly, so open -a "Neovide" {filename} will avoid opening multiple windows. This solves the issue at least on macOS.

chrisgrieser avatar May 17 '24 10:05 chrisgrieser

@fredizzimo sorry to bother you, but I do not think this issue is fully resolved. Just one case (opening via open on macOS) is solved, opening via neovide (the CLI) still spawns new windows.

Other than not working on systems other than macOS, opening via neovide is still relevant for various use cases (tmux described here, to open at a specific line via rg, …)

chrisgrieser avatar May 17 '24 23:05 chrisgrieser

Yes, re-opening this, I thought we had another cross-platform issue for it, since it's the same on all other platforms, we don't have a built-in way of re-using the same Neovide instance. We had this https://github.com/neovide/neovide/issues/1293, but it was closed in favour of this one.

With a few shell commands it's easy to support though:

  1. Start the server nvim --headless --listen localhost:9034&
  2. Start Neovide and connect neovide --server localhost:9034
  3. Edit a file nvim --server localhost:9034 --remote-tab $PWD/file.txt or nvim --server localhost:9034 --remote-edit $PWD/file.txt

You can replace the port 9034, by any free TCP port on your system, I just selected a number randomly. If you want multiple instances you can use multiple ports

Note, you need to full path to the file, if you started the instance in another folder, that's why I added $PWD

If you use it much, then a shell alias could be created alias neovide-open='nvim --server localhost:9034 --remote-tab' and used like this neovide-open $PWD/file.txt`. But in practice you probably want something a bit smarter than that, that automatically converts relative paths to absolute, and supports multiple arguments. I leave that as an exercise for the reader.

fredizzimo avatar May 18 '24 10:05 fredizzimo

Yeah, I am using sth similar to that as a workaround currently, though it is quite cumbersome.

It's also not very beginner friendly for people starting out with nvim.

chrisgrieser avatar May 18 '24 12:05 chrisgrieser

I've tried both

alias nvim='open -a "Neovide"'

and I've tried

function nvim() {
  local nvim_socket
  nvim_socket=/tmp/neovide.socket

  if [ ! -S $nvim_socket ]; then
    nvim --server $nvim_socket --remote-edit $PWD/file.txt
  else
    nvim --headless --listen $nvim_socket &
    neovide --server $nvim_socket
  fi
}

but both those options seem to have significantly worse performance for me than just running

neovide $filename

Scrolling is buttery smooth via neovide but regularly chokes and stutters using either of the other options when navigating a huge ruby file (full of lines longer than lines have any right to be).

Would anyone have any suggestions why that might be, or what else I might try to get the normal neovide performance, while being able to add new buffers to the same instance from the cli?

lparry avatar Jul 02 '24 06:07 lparry

Overall Neovide is the best GUI for neovim, but this one annoying thing makes it difficult to work with. Its reasonable to expect to have multiple windows, and not have many icons on deck. You can't switch between windows with "cmd+`" (like every other app). There's also no way to know which window you are choosing.

Is there no way to resolve this issue? this is a very unusual behaviour for a macos app.

mooktakim avatar Jul 10 '24 15:07 mooktakim

The reason is mostly lack of developers on macOS. It's also technically a quite big task.

I'm not a macOS developer myself, but all the documentation I have seen suggest that in order to have multiple windows grouped together they need to be created by the same process. This is very different from the other operating systems, where the OS/Window Manager/Compositor can group the windows together in the same icon without any special application support.

This means that in order to support this, we need to re-structure the code so that we can maintain connections to several different Neovim instances, where each instance will render into its own window. It's not that hard to do, but we do use a few globals for example, which we would need to get rid of.

fredizzimo avatar Jul 10 '24 15:07 fredizzimo

ok, thanks for the explanation @fredizzimo 👍

mooktakim avatar Jul 10 '24 15:07 mooktakim