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>