From fc5cac570e7fa2dd9a9bde0881de6ea848046f23 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Sun, 17 May 2026 12:54:24 +0800 Subject: [PATCH] Bump ttimeoutlen to 50ms on SSH/TTY (#75) * Bump ttimeoutlen to 50ms on SSH/TTY ttimeoutlen=10 fragments multi-byte key codes (F-keys, arrows, Alt- prefixes) when one-way latency exceeds 10ms, which is normal on SSH. Vim then sees ESC followed by a literal letter and either returns to Normal mode mid-insert or treats the trailing byte as a separate keypress (so inserts "4"). 50ms is the standard "slow link" value: well below perceptible delay locally and big enough for typical residential/long-haul SSH. g:is_tty already gates several other terminal accommodations; reuse it here. Closes #74 * Pin TERM in ttimeoutlen test (env-hermetic) --- CHANGELOG.md | 4 ++++ modules/core.vim | 5 ++++- scripts/test.sh | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 497efe5..ee4f981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,10 @@ - README badge and `install.sh` recommend Vim 8.1+ instead of 8.0+ — the runtime conditionally relies on patches `8.1.0360` (diffopt) and `8.1.1517` (completeopt+=popup), so 8.0 users hit option errors +- `ttimeoutlen` is now 50ms when `g:is_tty` (was 10ms unconditionally); + fixes F-keys, arrow keys, and Alt-prefixes fragmenting on SSH where + one-way latency exceeds 10ms. Local terminals keep the 10ms snappy + default - `install.sh` no longer silently `PlugClean!`s user-added plugins from `~/.vim/plugged`; it now lists undeclared plugin directories first and asks before removing them (`--yes` skips the removal entirely) diff --git a/modules/core.vim b/modules/core.vim index 70d03b4..2194ff5 100644 --- a/modules/core.vim +++ b/modules/core.vim @@ -42,7 +42,10 @@ set noerrorbells set novisualbell set t_vb= set ttimeout -set ttimeoutlen=10 +" Wait long enough on SSH/TTY for multi-byte key codes to arrive intact — +" 10ms fragments F-keys, arrows, and Alt-prefixes when one-way latency > 10ms. +" 50ms is well under perceptible →Normal delay locally. +let &ttimeoutlen = g:is_tty ? 50 : 10 if $COLORTERM ==# 'gnome-terminal' set t_Co=256 diff --git a/scripts/test.sh b/scripts/test.sh index efa5815..e3759e8 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -257,6 +257,14 @@ check_vim() { -c 'if maparg(",F", "n") !~# "gg=G" | cquit | endif' \ -c 'qa!' 2>&1 + TERM=xterm-256color XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \ + -c 'if g:is_tty || &ttimeoutlen != 10 | cquit | endif' \ + -c 'qa!' 2>&1 + + TERM=linux XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \ + -c 'if !g:is_tty || &ttimeoutlen != 50 | cquit | endif' \ + -c 'qa!' 2>&1 + XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \ -c 'silent! delcommand LspStatus' \ -c 'silent! delcommand LspInstallServer' \