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.
This commit is contained in:
Johannes Altmanninger
2025-03-19 09:12:03 +01:00
parent 841687a1af
commit 733f704267
2 changed files with 13 additions and 7 deletions

View File

@@ -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

View File

@@ -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