doctorfree / nvim-lazyman

Neovim configuration manager and Lazy/Lua/Mason based Neovim config. Manage multiple Neovim configurations with the lazyman command. ☕
https://lazyman.dev
MIT License
263 stars 8 forks source link

question: how to link to specific distribution from neovide outside WSL #71

Closed rdataforge closed 2 months ago

rdataforge commented 3 months ago

I use Neovide installed on windows but as interface of the WSL installed neovim. I have bob and lazyman working ok in WSL. As per documentation in neovide you can use it to connect to WSL neovim version if the shortcut is:

neovide --wsl

but my issue is that it opens a plain simple neovim with no config at all and i want to use AstroNvim (or any other lazyman installed distribution)

there is a way to force neovide to read a specific path for the bin - neovim folder if you set the shortcut this way:

neovide --wsl --neovim-bin ~/.local/share/bob/nvim-bin/nvim

but this still opened a simple plain nvim.

i guess which is the correct path to open the distribution i wanted.

any hint will be much appreciated and thanks for an excellent piece of software!

doctorfree commented 3 months ago

I do not have a Windows box to help figure this out. I don't run Windows nor do I target Windows as a platform for any of my projects. That being said, I would like to help you so I will make some suggestions without being able to test them first.

Neovim 0.9+ uses the NVIM_APPNAME environment variable to determine where to look for its configuration files, plugins, cache, and state. The default location for the configuration files is ~/.config/nvim/. Lazyman does not install any configuration files in that default location. Rather, it uses alternate folder names in ~/.config/ and sets the NVIM_APPNAME environment variable accordingly. My guess is that Neovim in your WSL environment is looking for its configuration in ~/.config/nvim/ but none exists there.

If this is the case, WSL Neovim is looking in the default location for configuration but none is there, then you can either link the configuration folder you want to use to that default location (not a very good approach but it may work) OR you can figure out how to set the NVIM_APPNAME environment variable when neovide kicks off Neovim in WSL. I don't know how that all works in Windows. Is there a way to pass environment variables into WSL? If so then do whatever is the equivalent in Windows of:

export NVIM_APPNAME="nvim-AstroNvimV4"

Where ~/.config/nvim-AstroNvimV4 is the configuration folder you want to use.

Does that make sense? Sorry, I do not know Windows well so you are on your own figuring out how to pass environment variables into WSL.

Also, there is a Neovide configuration file that can be used to set some Neovide defaults. This is a TOML format file in /Wherever/on/Windows/neovide/config.toml that has entries like:

wsl = false
no-multigrid = false
vsync = true
maximized = false
srgb = false
idle = true
neovim-bin = "/usr/bin/nvim" # in reality found dynamically on $PATH if unset
frame = "full"
title-hidden = true
tabs = true

You could use this file to avoid having to specify the Neovide command line arguments every time.

rdataforge commented 3 months ago

Thanks for your quick response. I think i owe you a better explanation of the WSL thingy.

You can run any lazyman installed WSL neovim the same way as any linux box. I just type “nvims” and choose the distribution i wanted or type “lazyman” and use the menus. Same as linux as in fact is ubuntu linux. Think of it as a virtual machine linux os (virtualbox maybe?). A window opened to linux inside Windows 10. Similar to when you open a terminal connected to a remote server with linux installed.

So no need to pass environment variables to neovide as neovide just “channels” the connection to neovim and adds some interface fancy. Neovide is only behaving as an interface (a window, so to speak) connected to the linux ubuntu neovim. Same as if you installed neovide on Gnome or KDE and opened nvim with it.

So, when you say to type export NVIM_APPNAME="nvim-AstroNvimV4”. That is not needed as i have it in my .bashrc inside WSL. So when I type nvim AstroNvim is opened.

the main issue here is to connect the neovide command to the command that opens the distribution in a way similar to this:

nvim /path/to/desired/config # if this really exists in a lazyman installed neovim

at the moment seems that neovide does not load the config files and just loads a clean neovim, which does not make sense as the command that neovide starts is nvim , and typing nvim in WSL opened AstroNvim hope this helps

doctorfree commented 3 months ago

Thanks for the clarification, I probably do not understand your environment well enough but it is interesting. How was Neovide installed? Is it a Windows application? That is, neovide is not itself in WSL but somehow invokes the WSL Neovim from outside of WSL? This was my understanding from your initial description but I wish to confirm.

If Neovide is running under Windows do we know if the --wsl argument runs a login shell? If not then your .bashrc may not be sourced as part of the shell in which Neovim will run. Regardless, my best guess is still the absence of any NVIM_APPNAME environment variable in whatever shell WSL is using to run Neovim.

Lazyman runs Neovide with something like NVIM_APPNAME="nvim-AstroNvimV4" neovide .... Is it possible in your environment to invoke Neovide with an NVIM_APPNAME setting on the command line in a similar way? That is, I am still looking for a way to pass an environment variable into WSL.

If Neovide is not a Windows app but is running in WSL then my comments here are not relevant. Similarly, if the --wsl argument to Neovide kicks off a login shell then I'll have to rethink.

doctorfree commented 3 months ago

@rdataforge if the problem really is a missing NVIM_APPNAME environment variable then perhaps this article will help:

https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/

This describes how to share environment variables between WSL and Windows by setting WSLENV. An example from the article:

WSLENV=GOPATH/l:USERPROFILE/w:SOMEVAR/wp

This syntax is pretty ugly so may take some playing around with to set NVIM_APPNAME in this way.

rdataforge commented 3 months ago

yes, neovide is installed as a windows application, but if you set the --wsl argument, then neovide searchs the nvim executable in the ubuntu machine and uses it. If not, neovide uses the neovim in windows if installed. Seems that it does not run a login shell as the neovim it opened is a clean one.

doctorfree commented 3 months ago

You can try setting the NVIM_APPNAME environment variable on the Windows side with something like:

setx NVIM_APPNAME "nvim-AstroNvimV4"

Where nvim-AstroNvimV4 is the Neovim configuration directory you want to use in WSL.

Then set WSLENV to include NVIM_APPNAME with something like:

setx WSLENV NVIM_APPNAME/u

You may need to fiddle with this, I have not tried this - these are just suggestions.

Another approach would be to install Neovide in WSL either directly or using lazyman. I have not tried that either as I do not have Windows or WSL. From my reading, the WSLENV environment variable should serve as a way to pass environment variables between Windows and WSL.

doctorfree commented 2 months ago

@rdataforge did setting the NVIM_APPNAME and WSLENV environment variables resolve this issue?

rdataforge commented 2 months ago

Sorry for the late response. Had to re-install my system. Good news is this approach worked. Thanks a lot