fix(window): keep window commands typed after timeoutlen in vscode

Once 'timeoutlen' passes after a lone <C-w>, nvim runs its builtin window
command, which reads the next key without mappings, so the vscode window
mappings were skipped (e.g. <C-w>c closed the nvim window instead of the
editor).

Map a lone <C-w> to read the next key and feed the whole command again,
with its count, remapped when one of the window mappings handles it
(special keys like <C-w><C-Down> included).

Fixes #2466
This commit is contained in:
dualfroz committed 2026-10-03 02:24:35 +02:00
1 parent 17cff16264
commit 955555921e
2 files changed
+28 -1

No files matched your search

@@ -34,6 +34,14 @@ function! s:manageEditorWidth(...)
endfor
endfunction
" A lone <C-w> runs the builtin window command once 'timeoutlen' passes, and that reads the next key
" without mappings, skipping the ones below. Read the key here instead and feed the whole command
" again, remapped when one of them handles it.
function! s:windowCommand(mode) abort
let keys = "\<C-w>" . getcharstr()
call feedkeys((v:count ? v:count : '') . keys, (empty(maparg(keytrans(keys), a:mode)) ? 'n' : 'm') . 'i')
endfunction
command! -complete=file -nargs=? Split call <SID>split('h', <q-args>)
command! -complete=file -nargs=? Vsplit call <SID>split('v', <q-args>)
command! -complete=file -nargs=? New call <SID>split('h', '__vscode_new__')
@@ -46,6 +54,9 @@ AlterCommand new New
AlterCommand vne[w] Vnew
AlterCommand on[ly] Only
nnoremap <C-w> <Cmd>call <SID>windowCommand('n')<CR>
xnoremap <C-w> <Cmd>call <SID>windowCommand('x')<CR>
" buffer management
nnoremap <C-w>n <Cmd>call <SID>splitNew('h', '__vscode_new__')<CR>
xnoremap <C-w>n <Cmd>call <SID>splitNew('h', '__vscode_new__')<CR>
@@ -6,7 +6,7 @@ import { strict as assert } from "assert";
import vscode, { Selection } from "vscode";
import { NeovimClient } from "neovim";
import { wait } from "../../utils";
import { wait, waitUntil } from "../../utils";
import {
attachTestNvimClient,
@@ -345,6 +345,22 @@ describe("VSCode integration specific stuff", () => {
);
});
it("Window commands typed after timeoutlen still go to vscode #2466", async () => {
await openTextDocument({ content: "blah" });
const timeoutlen = (await client.getOption("timeoutlen")) as number;
await client.setOption("timeoutlen", 100);
try {
await sendNeovimKeys(client, "<C-w>", 500);
await sendNeovimKeys(client, "v");
await waitUntil(() =>
assert.equal(vscode.window.tabGroups.all.length, 2, "<C-w>v should split the editor"),
);
} finally {
await client.setOption("timeoutlen", timeoutlen);
await vscode.commands.executeCommand("workbench.action.joinAllGroups");
}
});
it("Opens a file through e command", async () => {
const filePath = path.join(os.tmpdir(), Math.random().toString());
fs.writeFileSync(filePath, ["line 1"].join("\n"), {