Share some key bindings with Vi's insert mode

This commit is contained in:
Johannes Altmanninger 2022-04-24 21:15:36 +02:00
parent cfce285a05
commit c34e694126
3 changed files with 26 additions and 39 deletions

View file

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

View file

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

View file

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