diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 20bb31e6e..f42983dff 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -166,6 +166,32 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod # Only insert spaces if we're either quoted or not at the beginning of the commandline # - this strips leading spaces if they would trigger histignore. bind --preset -M paste " " self-insert-notfirst + + # Bindings that are shared in text-insertion modes. + if not set -l index (contains --index -- -M $argv) + or test $argv[(math $index + 1)] = insert + + # This is the default binding, i.e. the one used if no other binding matches + bind --preset $argv "" self-insert + or exit # protect against invalid $argv + + # Space and other command terminators expands abbrs _and_ inserts itself. + bind --preset $argv " " self-insert expand-abbr + bind --preset $argv ";" self-insert expand-abbr + bind --preset $argv "|" self-insert expand-abbr + bind --preset $argv "&" self-insert expand-abbr + bind --preset $argv "^" self-insert expand-abbr + bind --preset $argv ">" self-insert expand-abbr + bind --preset $argv "<" self-insert expand-abbr + # Closing a command substitution expands abbreviations + bind --preset $argv ")" self-insert expand-abbr + # Ctrl-space inserts space without expanding abbrs + bind --preset $argv -k nul 'commandline -i " "' + + + bind --preset $argv \n execute + bind --preset $argv \r execute + end end function __fish_commandline_insert_escaped --description 'Insert the first arg escaped if a second arg is given' diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index 44311ad87..a0ea7aa2a 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -27,27 +27,6 @@ function fish_default_key_bindings -d "emacs-like key binds" __fish_shared_key_bindings $argv or return # protect against invalid $argv - # This is the default binding, i.e. the one used if no other binding matches - bind --preset $argv "" self-insert - or exit # protect against invalid $argv - - # Space and other command terminators expands abbrs _and_ inserts itself. - bind --preset $argv " " self-insert expand-abbr - bind --preset $argv ";" self-insert expand-abbr - bind --preset $argv "|" self-insert expand-abbr - bind --preset $argv "&" self-insert expand-abbr - bind --preset $argv "^" self-insert expand-abbr - bind --preset $argv ">" self-insert expand-abbr - bind --preset $argv "<" self-insert expand-abbr - # Closing a command substitution expands abbreviations - bind --preset $argv ")" self-insert expand-abbr - # Ctrl-space inserts space without expanding abbrs - bind --preset $argv -k nul 'commandline -i " "' - - - bind --preset $argv \n execute - bind --preset $argv \r execute - bind --preset $argv \ck kill-line bind --preset $argv \eOC forward-char diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index e0f8f6d7b..284c0303f 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -50,24 +50,6 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' __fish_shared_key_bindings -s -M $mode end - bind -s --preset -M insert \r execute - bind -s --preset -M insert \n execute - - bind -s --preset -M insert "" self-insert - - # Space and other command terminators expand abbrs _and_ inserts itself. - bind -s --preset -M insert " " self-insert expand-abbr - bind -s --preset -M insert ";" self-insert expand-abbr - bind -s --preset -M insert "|" self-insert expand-abbr - bind -s --preset -M insert "&" self-insert expand-abbr - bind -s --preset -M insert "^" self-insert expand-abbr - bind -s --preset -M insert ">" self-insert expand-abbr - bind -s --preset -M insert "<" self-insert expand-abbr - # Closing a command substitution expands abbreviations - bind -s --preset -M insert ")" self-insert expand-abbr - # Ctrl-space inserts space without expanding abbrs - bind -s --preset -M insert -k nul 'commandline -i " "' - # Add a way to switch from insert to normal (command) mode. # Note if we are paging, we want to stay in insert mode # See #2871