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

Running Neovim in Vim's terminal triggers E5009 (uses Vim's VIM/VIMRUNTIME) #8696

Closed
blueyed opened this issue Jul 6, 2018 · 17 comments
Closed
Labels
closed:wontfix current behavior is by design, and change is not desired environment user system environment (terminal, shell, tmux) terminal built-in :terminal or :shell
Milestone

Comments

@blueyed
Copy link
Contributor

blueyed commented Jul 6, 2018

Vim appears to set $VIM and $VIMRUNTIME in its terminal environment, which then gets picked up by Neovim.

Running :checkhealth will trigger:

E5009: Invalid $VIMRUNTIME: /usr/share/vim/vim81

The workaround is to unset VIM/VIMRUNTIME before running nvim.

Vim 8.1.22
NVIM v0.3.1-139-g2bfabd5b

@blueyed
Copy link
Contributor Author

blueyed commented Jul 6, 2018

Vim behaves the same (it also uses an existing $VIM/VIMRUNTIME from Neovim's terminal), but there has('python3') still works.

Not sure if anything can be improved here really - feel free to close it.

@justinmk
Copy link
Member

justinmk commented Jul 6, 2018

Yeah, this is a pain point for me. We need to undefine VIMRUNTIME, NVIM_LISTEN_ADDRESS, etc. in :terminal. Been waiting on #7202 but maybe we can do something else in the meantime.

@justinmk
Copy link
Member

justinmk commented Jul 6, 2018

Oops I got your report mixed up. I thought Vim already undefined VIMRUNTIME in its :terminal. There's not really anything we can do about Vim's :terminal ....

@justinmk justinmk added the terminal built-in :terminal or :shell label Jul 6, 2018
@blueyed
Copy link
Contributor Author

blueyed commented Jul 6, 2018

undefine VIMRUNTIME, NVIM_LISTEN_ADDRESS, etc.

Maybe it would be better to not pick it up during startup?
It might be useful to see if there is an outer (Neo)vim after all.
Maybe VIMRUNTIME could be unset, but not VIM or something in this direction - or another new environment variable could be set to indicate that this is :terminal?

I came across this when trying to improve vim-tmux-navigator when used nested (via christoomey/vim-tmux-navigator#201). But there appears to be no autocommand for when an inner Neovim is entered it seems. Maybe FocusGained (should) get(s) triggered?! (i.e. the outer Neovim should send the escape sequences when entering/leaving a terminal window?! (if focus reporting is enabled)

@janlazo
Copy link
Contributor

janlazo commented Jul 6, 2018

@blueyed Did you try detecting VIM_SERVERNAME?

@jamessan
Copy link
Member

jamessan commented Jul 6, 2018

Vim added a $VIM_TERMINAL environment variable (c.f., 8.1.0049 and 8.1.0050) so programs can know when they're running inside a vim :terminal.

@jamessan
Copy link
Member

jamessan commented Jul 6, 2018

We need to undefine VIMRUNTIME, NVIM_LISTEN_ADDRESS, etc. in :terminal

Then how would programs in :terminal communicate back to their containing nvim (like page does)?

@justinmk justinmk added this to the todo milestone Jan 27, 2019
@justinmk justinmk added good first issue complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md labels Jan 27, 2019
@justinmk justinmk modified the milestones: todo, 0.5 Dec 12, 2019
@aspieln3r
Copy link

I would like to work on this issue.
The solution seems to be checking for $VIM_TERMINAL and then if set, unset $VIM and $VIMRUNTIME.
Can someone guide me from here?

@drosan-dev
Copy link

I unset VIM VIMRUNTIME when nvim start

@drosan-dev
Copy link

#12759

@shinymimiq
Copy link

unset VIM and VIMRUNTIME will still cause problem when call :checkhealth in Nvim inside of vim terminal because we need valid VIM and VIMRUNTIME for :checkhealth

What about we handle this special case inside our vim_getenv function.
We can check if we are trying to get VIMRUNTIME or VIM inside of vim terminal, if so, we should assume those are empty and set them as we do normally.
e.g #14838

@shinymimiq shinymimiq mentioned this issue Jun 17, 2021
@jamessan
Copy link
Member

We can check if we are trying to get VIMRUNTIME or VIM inside of vim terminal, if so, we should assume those are empty and set them as we do normally.

What if I'm trying to run against a custom runtime from with a vim terminal? VIMRUNTIME=... nvim foo would be the typical way to do that, but you're suggesting to just ignore the explicitly set VIMRUNTIME because VIM_TERMINAL is set?

There are really two problems here.

  • nvim stuck with the same environment variables Vim uses.
  • Both programs export VIM/VIMRUNTIME to the environments of their child processes

I don't recall (and don't feel like looking right now) whether the latter point has been discussed for Vim. However, it seems those two variables should not be exported into child processes. Then we would know for sure that if they're set, it's because the user did so.

VIM_SERVERNAME/NVIM_LISTEN_ADDRESS should still be exported to child processes, since that allows communicating with the containing process (including querying them for their VIMRUNTIME if needed).

@shinymimiq

This comment was marked as outdated.

@clason clason modified the milestones: 0.6, 0.7 Nov 30, 2021
@zeertzjq zeertzjq added the environment user system environment (terminal, shell, tmux) label Dec 1, 2021
@clason
Copy link
Member

clason commented Dec 15, 2021

Duplicate of #6764, so I'm closing this one. (Feel free to reopen and close the other one instead.)

@clason clason closed this as completed Dec 15, 2021
@zeertzjq
Copy link
Member

No, this is not a duplicate. This is about running Nvim in Vim's terminal, that one is about running Vim in Nvim's terminal.

@zeertzjq zeertzjq reopened this Dec 15, 2021
@clason
Copy link
Member

clason commented Dec 15, 2021

Whoops! Only consolation is that Justin made the same mistake (#8696 (comment)) 😄

justinmk added a commit to justinmk/neovim that referenced this issue May 2, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to v:servername, *only* in child processes.
   - Now the correct way to detect a "host" or "parent" Nvim is to check
     for $NVIM env var.
2. Do NOT set $NVIM_LISTEN_ADDRESS child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

This also fixes the "Failed to start server" spam in our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
justinmk added a commit to justinmk/neovim that referenced this issue May 2, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to v:servername, *only* in child processes.
   - Now the correct way to detect a "host" or "parent" Nvim is to check
     for $NVIM env var.
2. Do NOT set $NVIM_LISTEN_ADDRESS child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

This also fixes the "Failed to start server" spam in our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
justinmk added a commit to justinmk/neovim that referenced this issue May 2, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to v:servername, *only* in child processes.
   - Now the correct way to detect a "host" or "parent" Nvim is to check
     for $NVIM env var.
2. Do NOT set $NVIM_LISTEN_ADDRESS child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

This also fixes the "Failed to start server" spam in our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
justinmk added a commit to justinmk/neovim that referenced this issue May 2, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to v:servername, *only* in child processes.
   - Now the correct way to detect a "host" or "parent" Nvim is to check
     for $NVIM env var.
2. Do NOT set $NVIM_LISTEN_ADDRESS child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
justinmk added a commit to justinmk/neovim that referenced this issue May 2, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to the parent v:servername, *only* in child processes.
   - Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
justinmk added a commit that referenced this issue May 3, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to the parent v:servername, *only* in child processes.
   - Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes #3118
Fixes #6764
Fixes #9336
Ref #8247 (comment)
Ref #8696
@justinmk
Copy link
Member

justinmk commented May 3, 2022

Nothing we can do about this. Not a bug. Could be a feature request to Vim.

@justinmk justinmk closed this as completed May 3, 2022
dmitmel pushed a commit to dmitmel/neovim that referenced this issue May 18, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to the parent v:servername, *only* in child processes.
   - Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
kraftwerk28 pushed a commit to kraftwerk28/neovim that referenced this issue Jun 1, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to the parent v:servername, *only* in child processes.
   - Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
github-actions bot pushed a commit that referenced this issue Jun 16, 2022
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to the parent v:servername, *only* in child processes.
   - Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes #3118
Fixes #6764
Fixes #9336
Ref #8247 (comment)
Ref #8696

(cherry picked from commit b9d97f5)
justinmk added a commit that referenced this issue Jun 17, 2022
…18986)

feat(server): introduce $NVIM

PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to the parent v:servername, *only* in child processes.
   - Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes #3118
Fixes #6764
Fixes #9336
Ref #8247 (comment)
Ref #8696

(cherry picked from commit b9d97f5)

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
@zeertzjq zeertzjq modified the milestones: 0.9, 0.8 Aug 18, 2022
@zeertzjq zeertzjq removed the complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md label Mar 18, 2023
@zeertzjq zeertzjq closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2023
@zeertzjq zeertzjq added the closed:wontfix current behavior is by design, and change is not desired label Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:wontfix current behavior is by design, and change is not desired environment user system environment (terminal, shell, tmux) terminal built-in :terminal or :shell
Projects
None yet
Development

Successfully merging a pull request may close this issue.