WSL port 7/7: bind the quit chord that WSL actually sends

Merged
JA
3mo ago
+162-41

Stacked on #12. Found by pressing the key — which is exactly what checkpoint 5
said would be needed, because nothing automated can reach this.

What was wrong

Ctrl+Shift+Q did nothing on WSL.

Windows Terminal 1.24 is new enough to speak CSI-u and does not negotiate it
with nvim. So the chord arrives as the legacy 0x11 — plain <C-q> — and the
<C-S-q> mapping is never reached. The documented way out of the editor did not
exist on WSL, leaving :qa! — the one thing that whole section of the config
was written to stop being necessary.

Why no test caught it

  • suite_quit.sh writes ESC[113;6u straight onto the pty, so it passes on
    a terminal where the chord could never arrive.
  • demo.sh --check cannot send CSI-u over --remote-send at all (checkpoint 4).
  • vim.g.termfeatures is nil even in a real TUI on nvim 0.12, so there is no
    runtime signal to detect CSI-u from Lua either.

This one genuinely required a human to press it.

The fix

Bind what actually arrives. This is not a second key to learn — you press
Ctrl+Shift+Q, exactly as documented, and <C-q> is what nvim is handed.

Insert only, and gated on WSL, because both halves cost something:

  • normal mode keeps Ctrl+Q as visual block — it is the only way to ask for
    one, and drill's premise is that you are in insert anyway
  • in insert, vanilla <C-q> is literal-insert, the twin of <C-v>. In a
    Python scratchpad where <C-v> is already paste that is close to unreachable,
    and a quit prompt defaulting to Cancel is the better use of the key. But it is
    a real vim behaviour, so nowhere but WSL loses it.

Verification — both branches, forced each way

On WSL:

insert  <C-q>   : -> quit_drill (callback)
normal  <C-q>   : <C-V>
insert  <C-S-q> : -> quit_drill (callback)
insert  <C-v>   : <C-R><C-O>+

Forced non-WSL — what a Mac sees:

insert  <C-q>   : UNMAPPED (vanilla literal-insert)
normal  <C-q>   : <C-V>
insert  <C-S-q> : -> quit_drill
insert  <C-v>   : <C-R><C-O>+

Byte-for-byte the old behaviour off WSL.

Suite: 556/556, ALL SUITES PASSED. Every <C-q> case in the suite is
normal-mode (suite_options.sh asserts it maps to <C-V>; suite_comment.sh's
visual-block case is --start normal), so none of them touch the new binding.

The WSL probe is hoisted to one IS_WSL near the top, since the clipboard
fallback asks the same question.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WveBqAyhoM49p9gWfwBDBx


Summary by cubic

Make the quit chord work on WSL by binding what Windows Terminal actually sends. On WSL, insert- and terminal‑mode <C-q> opens the quit prompt; normal‑mode <C-q> stays visual block. Off WSL, behavior is unchanged.

  • Bug Fixes

    • WSL: map insert- and terminal‑mode <C-q> to the quit prompt because Windows Terminal 1.24 doesn’t negotiate CSI‑u with nvim and sends 0x11; lets you quit from inside the REPL while keeping normal‑mode <C-q> for visual block.
    • Docs: clarify the IS_WSL gate (env, not protocol), the normal‑mode gap on non‑CSI‑u terminals, terminal‑mode quit, the insert‑mode literal‑insert trade‑off, and retract the earlier --remote-send collapse claim.
  • Refactors

    • Hoisted a single IS_WSL probe and applied the fallback in insert and terminal modes.
    • Tests: add suite_options.sh checks to ensure the <C-q> fallback binds only on WSL (i/t) and does not leak to Linux CI.
    • Comments: note readline binds ^Q to quoted‑insert; the fallback trades it for quit, with ^V still providing quoted‑insert.

Summary by CodeRabbit

  • New Features
    • Added WSL support for terminals that send Ctrl+Shift+Q as Ctrl+Q.
    • In insert and terminal modes, the shortcut now opens the quit prompt; normal-mode Ctrl+Q retains visual-block selection.
    • Terminals supporting CSI-u continue to use the dedicated Ctrl+Shift+Q behavior.
  • Documentation
    • Clarified terminal compatibility, WSL-specific key behavior, quit instructions, and automated testing limitations.

Greptile Summary

The PR makes the documented quit chord work when Windows Terminal sends its legacy <C-q> encoding under WSL.

  • Adds a WSL-gated <C-q> fallback in insert and terminal modes while preserving normal-mode visual block.
  • Documents the CSI-u limitation and intentional keybinding trade-offs.
  • Adds platform-sensitive assertions that the fallback is present only on WSL.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the current WSL-gated mapping includes both insert and terminal modes, so the previously reported missing REPL fallback is fixed.

Important Files Changed

FilenameOverview
nvimrc.luaAdds the missing terminal-mode fallback alongside insert mode, fully addressing the previous review thread while preserving normal-mode <C-q>.
tests/suite_options.shVerifies that callback mappings exist in insert and terminal modes exactly when the shared WSL detection is true.
KEYS.mdDocuments the non-CSI-u normal-mode limitation and the WSL-specific fallback behavior.
docs/wsl.mdExplains the terminal encoding behavior, affected modes, and deliberate loss of literal insert on WSL.
TODO.mdUpdates checkpoint evidence and records the manually verified WSL key-encoding behavior.

Reviews (25): Last reviewed commit: "Test the WSL quit fallback, and stop cal..." | Re-trigger Greptile