在 GUI 會話下的終端機中,Oo 產生“/”字符

在 GUI 會話下的終端機中,Oo 產生“/”字符

在 Ubuntu 20.10 下的 GNOME3 GUI 登入工作階段中,在終端機視窗中快速連續按ESCOo會產生「/」字符,而不是輸入這些按鍵。當執行 Vim 時,這是有問題的,我經常想打破插入模式並在當前文字上方快速開始一個新文字行。

以 開頭的其他鍵序列的ESC O行為類似:ESC O q產生「1」; ... w“7”等。

在 Vim 中輸入這些鍵並觸發效果的時間視窗似乎約為 2 秒,而在命令列中則短得多。

透過控制台登入時CTRL ALT F6,不會觀察到此行為。

它也不會出現在 Chrome、文字編輯器或 GVim 等其他應用程式中。

它確實出現在 Guake 和 Terminal 下。

我還在 Windows 10 電腦上的 Ubuntu WSL 安裝中觀察到相同的行為。兩個主目錄之間似乎沒有任何可疑的公共配置元素。

我還沒有檢查其他桌面(例如 LXDE 或 KDE)下的行為。

我注意到這個問題不會出現在 MacOS 終端機會話中。

這是 GNOME 的功能嗎?有什麼方法可以停用它或修改它嗎?

答案1

問題出在 VTE 的鍵盤映射中,來自2014年的這項變化:

提交 598572b526568591ca91e3e0019412274edd9643
作者:Egmont Koblinger[電子郵件受保護]
日期:2014 年 5 月 18 日星期日 13:36:01 +0200

keymap:使用硬編碼序列而不是 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 時,我只看到能夠將綁定分配給其中一個行動終端識別:

gnome 終端首選項

如果該方法沒有幫助,還有其他在 Ubuntu 上運行的終端。

答案2

TL;DR 檢查您的timeoutlen和/或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 個鍵。

既然你看到 vim 中的時間視窗是 2 秒,我猜你timeoutlen和/或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。查看手冊頁 urxvt(7),我看到:

KP_Divide      /       ESC O o

KP可能指的是數字鍵盤。

相關內容