Mapping with `<Esc>` after another key matches only the first byte of a kitty-protocol Esc

オープン
#21,683 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 13 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
cli

調査の方向性

Start with handle_mapping() in src/getchar.c and inspect how it calls check_termcode() when a mapping includes Escape after another key. Reproduce with the provided feedkeys() command or a kitty-protocol terminal, then trace how the remaining typeahead is handled. Done means CSI 27 u matches <Esc> in the mapping without leaving [27u behind, and plain Escape still works.

索引モデルが issue の本文から書いたものです。

説明

Steps to reproduce
  1. Start vim --clean in a terminal where Vim enables the kitty keyboard protocol. I used Ghostty, which the default 'keyprotocol' matches with ghostty:kitty.
  2. :nnoremap <Leader><Esc> <Nop>
  3. Make nine changes: o1<Esc>, o2<Esc>, and so on through o9<Esc>.
  4. Press \, then <Esc>.

The mapping runs, and then the last seven changes are undone ("7 fewer lines; before #3"). I first noticed this with nnoremap <Leader><Esc> :nohlsearch<CR>.

With the kitty protocol, Esc arrives as CSI 27 u (ESC [ 2 7 u). The mapping matches \ plus only the first byte of that sequence, and [27u is left in the typeahead. [2 fails, and 7u undoes seven changes.

The same thing happens without a kitty terminal (tested with TERM=xterm-256color) if step 4 is replaced with:

:call feedkeys("\\\<Esc>[27u", "L")

The cause appears to be in handle_mapping() in src/getchar.c. check_termcode() runs only when no mapping fully matched, or when the full match is a lone ESC (mp_match_len == 1 && *mp->m_keys == ESC). A mapping where <Esc> follows another key gets no such exception, so the raw ESC byte completes the mapping before CSI 27 u is translated to <Esc>.

Workaround: set keyprotocol-=ghostty:kitty followed by let &term = &term in the vimrc.

Expected behaviour

CSI 27 u matches <Esc> in the mapping the same way a plain ESC byte does: the mapping runs and no keys are left over. When the terminal sends a plain ESC byte, the mapping works and nothing is undone.

Version of Vim

9.1.1752 (macOS system Vim). Not tested on 9.2, but the logic described above is the same in v9.2.1252.

Environment

Operating system: macOS 26.7
Terminal: Ghostty 1.4.0
Value of $TERM: xterm-ghostty
Shell: bash 5.3.20

主要言語
Vim Script
スター
41.4k
フォーク
6.2k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vim/vim のほかの issue

vim/vim の issue をすべて見る

似ている issue

CLI の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。