From 33fe575112849405610499f65dd2232ed80a78fc Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 4 Aug 2024 02:55:04 +0700 Subject: [PATCH] Add more convenient key bindings for VI mode To make it more familiar to vi/vim users. In all mode, ctrl-k is bind to kill-line. In Vi visual mode: * press v or i turn into normal or insert mode respectively. * press I turn to insert mode and move the cursor to beginning of line. * because fish doesn't have upcase/locase-selection, and most people reach for g-U rather than g-u, g-U binds to togglecase-selection temporarily. (cherry picked from commit f9b79926f1a9aba7da9b6fb9076c764e127ae2ef) --- share/functions/__fish_shared_key_bindings.fish | 1 + share/functions/fish_vi_key_bindings.fish | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 13faef8ca..21febbeba 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -69,6 +69,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod bind --preset $argv ctrl-l clear-screen bind --preset $argv ctrl-c cancel-commandline bind --preset $argv ctrl-u backward-kill-line + bind --preset $argv ctrl-k kill-line bind --preset $argv ctrl-w backward-kill-path-component bind --preset $argv end end-of-line bind --preset $argv home beginning-of-line diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 00c279cdf..0a1ef6a9a 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -312,6 +312,9 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -M visual $key beginning-of-line end + bind -s --preset -M visual -m default v end-selection repaint-mode + bind -s --preset -M visual -m insert i end-selection repaint-mode + bind -s --preset -M visual -m insert I end-selection beginning-of-line repaint-mode bind -s --preset -M visual -m insert c kill-selection end-selection repaint-mode bind -s --preset -M visual -m insert s kill-selection end-selection repaint-mode bind -s --preset -M visual -m default d kill-selection end-selection backward-char repaint-mode @@ -321,6 +324,7 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -M visual -m default '",*,y' "fish_clipboard_copy; commandline -f end-selection repaint-mode" bind -s --preset -M visual -m default '",+,y' "fish_clipboard_copy; commandline -f end-selection repaint-mode" bind -s --preset -M visual -m default '~' togglecase-selection end-selection repaint-mode + bind -s --preset -M visual -m default g,U togglecase-selection end-selection repaint-mode bind -s --preset -M visual -m default ctrl-c end-selection repaint-mode bind -s --preset -M visual -m default escape end-selection repaint-mode