From 8e7885783644d1d828d8049ebf2af3401f92ee41 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. (cherry picked from commit 733f7042679e97bd8176d4958ed704f0dd92b2dd) --- CHANGELOG.rst | 1 + .../functions/__fish_shared_key_bindings.fish | 2 +- share/functions/fish_vi_key_bindings.fish | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 97e814c2c..88b3d1486 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,7 @@ fish 4.0.2 (released March ??, 2025) This release of fish includes the following improvements compared to fish 4.0.1: - Key combinations using the super (Windows/command) key can now actually be bound using the :kbd:`super-` prefix (:issue:`11217`). +- :kbd:`delete` in Vi mode works again if numlock is active (:issue:`11303`). - A crash involving backspace characters was fixed (:issue:`11280`). - Fish 4.0.0 switched completions to be quoted instead of backslash-escaped, now it only does so if the completion is unambiguous to make continuing the token easier (:issue:`11271`). diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index cff6d7d7d..aabf9fd72 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -120,7 +120,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod bind --preset $argv alt-enter "commandline -i \n" expand-abbr bind --preset $argv ")" self-insert expand-abbr # Closing a command substitution. bind --preset $argv ctrl-space 'test -n "$(commandline)" && commandline -i " "' - bind --preset $argv -k nul 'test -n "$(commandline)" && commandline -i " "' + $legacy_bind --preset $argv -k nul 'test -n "$(commandline)" && commandline -i " "' # Shift-space behaves like space because it's easy to mistype. bind --preset $argv shift-space 'commandline -i " "' expand-abbr diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index cb8428e17..56ab5baa3 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