Skip to content

fix(nvim): pass Esc through to an nvim nested in a workspace terminal - #1

Merged
baairon merged 1 commit into
mainfrom
claude/quirky-lamport-3d7mgh
Oct 6, 2026
Merged

baairon merged 1 commit into
mainfrom
claude/quirky-lamport-3d7mgh

Conversation

@baairon

@baairon baairon commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Problem

Running Claude Code's /plan open (or git 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 / :wq that followed then went to the outer nvim:

  • :q closed the terminal pane's window, so the pane looked wiped and blank. The nested nvim kept running in the hidden terminal buffer.
  • :wq failed with E382: 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 from layout.lua:

  • Nested side: on UIEnter, an nvim whose $NVIM names another nvim connects to it and reports in. On VimLeavePre it reports that it is leaving.
  • Outer side: the terminal buffer the nested nvim reported from gets a buffer-local nowait <Esc> that goes straight through to the nested nvim, with no timeoutlen delay. 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.
  • The Alt chords still reach the outer nvim, so moving between panes works the same while the nested nvim is open.
  • Only a terminal buffer can be marked. An nvim whose $NVIM is stale or points somewhere else does nothing.

Testing

  • In the tmux repro: typing text, double Esc, then :wq in the nested nvim now saves the file and exits 0. The pane stays, <Esc><Esc> leaves terminal mode again afterwards, and after a kill -9 of the nested nvim the mapping is removed on the next Esc.
  • Added checks to tests/runtime.lua. nvim --headless -u NONE -l tests/runtime.lua passes all 300 checks.
  • Not tested on Windows, where ConPTY and named pipes are used.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pr6jVTWbDwEJ4p8ZANoqzs


Generated by Claude Code

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
@baairon
baairon merged commit 3623b45 into main Oct 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants