From 733f7042679e97bd8176d4958ed704f0dd92b2dd Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 19 Mar 2025 09:12:03 +0100 Subject: [PATCH] Fix Vi mode delete key bindings while numlock is active Commit 8bf8b10f68 (Extended & human-friendly keys, 2024-03-30) add bindings that obsolete the terminfo-based `bind -k` invocations. The `bind -k` variants were still left around[^*]. Unfortunately it forgot to add the new syntax for some special keys in Vi mode. This leads to issues if a terminal that supports the kitty keyboard protocol sends an encoding that differs from the traditional one. As far as I can tell, this happens when capslock or numlock is active. Let's add the new key names and consistently mark `bind -k` invocations as deprecated. Fixes #11303 [^*]: Support for `bind -k` will probably be removed in a future release - it leads to issues like https://github.com/fish-shell/fish-shell/issues/11278 where it's better to fail early. --- .../functions/__fish_shared_key_bindings.fish | 2 +- share/functions/fish_vi_key_bindings.fish | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 02e5d07b6..2cb856f1d 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -139,7 +139,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod bind --preset $argv alt-enter "commandline -i \n $maybe_search_field" expand-abbr bind --preset $argv ")" self-insert expand-abbr # Closing a command substitution. bind --preset $argv ctrl-space 'test -n "$(commandline)" && commandline -i " " '$maybe_search_field - bind --preset $argv -k nul 'test -n "$(commandline)" && commandline -i " " '$maybe_search_field + $legacy_bind --preset $argv -k nul 'test -n "$(commandline)" && commandline -i " " '$maybe_search_field # Shift-space behaves like space because it's easy to mistype. bind --preset $argv shift-space 'commandline -i " " '$maybe_search_field expand-abbr diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 4b68e60d9..73690f27e 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -109,18 +109,24 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -M insert ctrl-n accept-autosuggestion # Vi/Vim doesn't support these keys in insert mode but that seems silly so we do so anyway. - bind -s --preset -M insert -k home beginning-of-line - bind -s --preset -M default -k home beginning-of-line - bind -s --preset -M insert -k end end-of-line - bind -s --preset -M default -k end end-of-line + bind -s --preset -M insert home beginning-of-line + $legacy_bind -s --preset -M insert -k home beginning-of-line + bind -s --preset -M default home beginning-of-line + $legacy_bind -s --preset -M default -k home beginning-of-line + bind -s --preset -M insert end end-of-line + $legacy_bind -s --preset -M insert -k end end-of-line + bind -s --preset -M default end end-of-line + $legacy_bind -s --preset -M default -k end end-of-line # Vi moves the cursor back if, after deleting, it is at EOL. # To emulate that, move forward, then backward, which will be a NOP # if there is something to move forward to. bind -s --preset -M default x delete-char 'set fish_cursor_end_mode exclusive' forward-single-char backward-char 'set fish_cursor_end_mode inclusive' bind -s --preset -M default X backward-delete-char - bind -s --preset -M insert -k dc delete-char forward-single-char backward-char - bind -s --preset -M default -k dc delete-char 'set fish_cursor_end_mode exclusive' forward-single-char backward-char 'set fish_cursor_end_mode inclusive' + bind -s --preset -M insert delete delete-char forward-single-char backward-char + $legacy_bind -s --preset -M insert -k dc delete-char forward-single-char backward-char + bind -s --preset -M default delete delete-char 'set fish_cursor_end_mode exclusive' forward-single-char backward-char 'set fish_cursor_end_mode inclusive' + $legacy_bind -s --preset -M default -k dc delete-char 'set fish_cursor_end_mode exclusive' forward-single-char backward-char 'set fish_cursor_end_mode inclusive' # Backspace deletes a char in insert mode, but not in normal/default mode. bind -s --preset -M insert backspace backward-delete-char