Repository navigation
fix(nvim): pass Esc through to an nvim nested in a workspace terminal - #1
Merged
Merged
Conversation
A program running $EDITOR in a workspace terminal (git commit, Claude Code's /plan open) starts a second nvim in that pane. The terminal's <Esc><Esc> mapping belongs to the outer nvim, so a double Esc typed in the nested one left terminal mode out there, and the :q or :wq after it closed the terminal pane instead. The nested nvim kept running hidden until it was killed, and Claude Code reported "Nvim quit unexpectedly (exit code 1)". The nested nvim now reports to the outer one over $NVIM, which gives that terminal a buffer-local nowait <Esc> that goes straight through until the nested nvim leaves, or dies and the next Esc finds its channel gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pr6jVTWbDwEJ4p8ZANoqzs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running Claude Code's
/plan open(orgit commit, or any other program that starts$EDITOR) in a workspace terminal starts a second nvim inside that pane. The terminal's<Esc><Esc>mapping belongs to the outer nvim, so a double Esc typed in the nested nvim switched the outer nvim out of terminal mode. The:q/:wqthat followed then went to the outer nvim::qclosed the terminal pane's window, so the pane looked wiped and blank. The nested nvim kept running in the hidden terminal buffer.:wqfailed withE382: Cannot write, 'buftype' option is set.When that hidden nvim was eventually killed, Claude Code reported
Nvim quit unexpectedly (exit code 1).I reproduced this on Linux by running your config in tmux, with a nested nvim inside a workspace bash terminal.
Fix
New module
nvim/lua/config/workspace/nested.lua, set up fromlayout.lua:UIEnter, an nvim whose$NVIMnames another nvim connects to it and reports in. OnVimLeavePreit reports that it is leaving.nowait<Esc>that goes straight through to the nested nvim, with notimeoutlendelay. When the nested nvim leaves, that mapping is removed and<Esc><Esc>works as before. If the nested nvim dies without reporting, the next Esc finds its channel gone and removes the mapping.$NVIMis stale or points somewhere else does nothing.Testing
:wqin the nested nvim now saves the file and exits 0. The pane stays,<Esc><Esc>leaves terminal mode again afterwards, and after akill -9of the nested nvim the mapping is removed on the next Esc.tests/runtime.lua.nvim --headless -u NONE -l tests/runtime.luapasses all 300 checks.🤖 Generated with Claude Code
https://claude.ai/code/session_01Pr6jVTWbDwEJ4p8ZANoqzs
Generated by Claude Code