GUIセッションのターミナルで、Ooは「/」文字を生成します

GUIセッションのターミナルで、Ooは「/」文字を生成します

Ubuntu 20.10 の GNOME3 GUI ログイン セッションで、ターミナル ウィンドウで、、をすばやく連続して押すと、ESCそれらのキーストロークが入力されるのではなく、「/」文字が生成されます。これは、挿入モードを終了して現在のテキストの上に新しい行をすばやく開始したいことが多い Vim の実行時に問題になります。Oo

で始まる他のキーシーケンスもESC O同様に動作します: ESC O q「1」、... w「7」などを生成します。多くも期待どおりに動作します。

これらのキーを入力して効果をトリガーするまでの時間枠は、Vim では約 2 秒ですが、コマンド ラインではかなり短くなります。

経由のコンソール ログイン中はCTRL ALT F6、この動作は観察されません。

また、Chrome、テキスト エディター、GVim などの他のアプリでも発生しません。

これは Guake と Terminal の両方で発生します。

また、Windows 10 マシン上の Ubuntu の WSL インストールでも同じ動作を確認しました。疑わしい 2 つのホーム ディレクトリ間には共通の構成要素はないようです。

LXDE や KDE などの他のデスクトップでの動作は確認していません。

この問題は MacOS ターミナル セッションでは発生しないことに気づきました。

これは GNOME の機能ですか? 無効にしたり変更したりする方法はありますか?

答え1

問題はVTEのキーマップにあります。2014年のこの変化:

コミット 598572b526568591ca91e3e0019412274edd9643
作成者: Egmont Koblinger[メールアドレス]
日付: 2014 年 5 月 18 日 (日) 13:36:01 +0200

キーマップ: terminfo の代わりにハードコードされたシーケンスを使用する

https://bugzilla.gnome.org/show_bug.cgi?id=728900#c5

ソースコードには次のように書かれています:

static const struct _vte_keymap_entry _vte_keymap_GDK_KP_Divide[] = {
        {cursor_all, keypad_default, 0, "/", 1},
        {cursor_all, keypad_app, VTE_NUMLOCK_MASK, "/", 1},
        {cursor_all, keypad_app, 0, _VTE_CAP_SS3 "o", -1},
        {cursor_all, keypad_all, 0, X_NULL, 0},
};

どこSS3シーケンスがたまたまそうなったEscapeO。一部の端末(およびおそらくgnome-terminalの一部のバージョン)ではキーの再定義が可能だが、Ubuntu 20をざっと確認したところ、キーの1つにバインディングを割り当てる機能しかなかった。行動端末が認識するもの:

gnome-terminal の設定

この方法が役に立たない場合は、Ubuntu で実行できる他のターミナルがあります。

答え2

timeoutlenTL;DR and/or ttimeoutlenvim オプションが高すぎないか確認してください。

これは Gnome に固有のものではありません。少し前にも同様の問題がありましたが、そのときは <Esc>Or が "2" を生成していました。

マクロ「oend^[Ores^[」は新しい行「end2es」になります。どのようにでしょうか?

ターミナルは、その下で実行されているプログラムに、エスケープ シーケンスとして特別なキー (またはF1など->) を提供します。vim がこれらのエスケープ シーケンスを解釈するか、各文字を独自に解釈するかを判断するために、タイマーを使用して、ユーザーがそれらを入力した可能性があるか、ターミナルがシーケンスを特別なキーへの変換として提供したか (入力するよりもはるかに高速であるはずです) を判断します。Vim は、これをオプションで説明していますesckeys

'esckeys' 'ek'      boolean (Vim default: on, Vi default: off)
            global
    Function keys that start with an <Esc> are recognized in Insert
    mode.  When this option is off, the cursor and function keys cannot be
    used in Insert mode if they start with an <Esc>.  The advantage of
    this is that the single <Esc> is recognized immediately, instead of
    after one second.  Instead of resetting this option, you might want to
    try changing the values for 'timeoutlen' and 'ttimeoutlen'.  Note that
    when 'esckeys' is off, you can still map anything, but the cursor keys
    won't work by default.
    NOTE: This option is set to the Vi default value when 'compatible' is
    set and to the Vim default value when 'compatible' is reset.
    NOTE: when this option is off then the |modifyOtherKeys| functionality
    is disabled while in Insert mode to avoid ending Insert mode with any
    key that has a modifier.

vim のデフォルト設定でこの動作を確認するには、3 つのキーを 10 分の 1 秒以内に入力する必要があります。

timeoutlenvim の時間ウィンドウが 2 秒になっているので、および/またはttimeoutlenvim のオプションが高すぎるのではないでしょうか。

                        *'timeoutlen'* *'tm'*
'timeoutlen' 'tm'   number  (default 1000)
            global

                        *'ttimeoutlen'* *'ttm'*
'ttimeoutlen' 'ttm' number  (default -1, set to 100 in |defaults.vim|)
            global
    The time in milliseconds that is waited for a key code or mapped key
    sequence to complete.  Also used for CTRL-\ CTRL-N and CTRL-\ CTRL-G
    when part of a command has been typed.
    Normally only 'timeoutlen' is used and 'ttimeoutlen' is -1.  When a
    different timeout value for key codes is desired set 'ttimeoutlen' to
    a non-negative number.

        ttimeoutlen mapping delay      key code delay   ~
           < 0      'timeoutlen'       'timeoutlen'
          >= 0      'timeoutlen'       'ttimeoutlen'

    The timeout only happens when the 'timeout' and 'ttimeout' options
    tell so.  A useful setting would be >
        :set timeout timeoutlen=3000 ttimeoutlen=100
    (time out on mapping after three seconds, time out on key codes after
    a tenth of a second).

さて、 は/特別なキーのようには思えないかもしれませんが、 の隣のキーとは異なって解釈されることが意図されているようですShift。man ページ urxvt(7) を見ると、次のことがわかります。

KP_Divide      /       ESC O o

KPおそらくテンキーを意味しています。

関連情報