2022-01-28 00:21:22 +00:00
|
|
|
function fish_default_key_bindings -d "emacs-like key binds"
|
2016-11-13 22:07:03 +00:00
|
|
|
if contains -- -h $argv
|
|
|
|
or contains -- --help $argv
|
|
|
|
echo "Sorry but this function doesn't support -h or --help"
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2016-11-13 21:39:55 +00:00
|
|
|
if not set -q argv[1]
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --erase --all --preset # clear earlier bindings, if any
|
2020-03-09 18:36:12 +00:00
|
|
|
if test "$fish_key_bindings" != fish_default_key_bindings
|
2016-11-13 21:39:55 +00:00
|
|
|
# Allow the user to set the variable universally
|
|
|
|
set -q fish_key_bindings
|
|
|
|
or set -g fish_key_bindings
|
2016-11-13 22:07:03 +00:00
|
|
|
# This triggers the handler, which calls us again and ensures the user_key_bindings
|
|
|
|
# are executed.
|
|
|
|
set fish_key_bindings fish_default_key_bindings
|
2016-11-13 21:39:55 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2017-10-03 08:29:48 +00:00
|
|
|
# Silence warnings about unavailable keys. See #4431, 4188
|
|
|
|
if not contains -- -s $argv
|
2020-03-09 18:36:12 +00:00
|
|
|
set argv -s $argv
|
2017-10-03 08:29:48 +00:00
|
|
|
end
|
|
|
|
|
2016-05-25 11:09:33 +00:00
|
|
|
# These are shell-specific bindings that we share with vi mode.
|
2016-09-03 21:00:41 +00:00
|
|
|
__fish_shared_key_bindings $argv
|
2016-11-28 05:27:22 +00:00
|
|
|
or return # protect against invalid $argv
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2016-11-13 21:39:55 +00:00
|
|
|
# This is the default binding, i.e. the one used if no other binding matches
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv "" self-insert
|
2016-11-28 05:27:22 +00:00
|
|
|
or exit # protect against invalid $argv
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2020-05-07 01:13:33 +00:00
|
|
|
# Space and other command terminators expands abbrs _and_ inserts itself.
|
2019-09-21 23:04:57 +00:00
|
|
|
bind --preset $argv " " self-insert expand-abbr
|
2020-05-07 01:13:33 +00:00
|
|
|
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
|
2020-03-19 17:18:11 +00:00
|
|
|
bind --preset $argv ")" self-insert expand-abbr
|
|
|
|
# Ctrl-space inserts space without expanding abbrs
|
2021-04-11 18:39:54 +00:00
|
|
|
bind --preset $argv -k nul 'commandline -i " "'
|
2020-03-19 17:18:11 +00:00
|
|
|
|
2019-04-01 13:59:15 +00:00
|
|
|
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \n execute
|
|
|
|
bind --preset $argv \r execute
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \ck kill-line
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \eOC forward-char
|
|
|
|
bind --preset $argv \eOD backward-char
|
|
|
|
bind --preset $argv \e\[C forward-char
|
|
|
|
bind --preset $argv \e\[D backward-char
|
|
|
|
bind --preset $argv -k right forward-char
|
|
|
|
bind --preset $argv -k left backward-char
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv -k dc delete-char
|
|
|
|
bind --preset $argv -k backspace backward-delete-char
|
|
|
|
bind --preset $argv \x7f backward-delete-char
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2016-11-13 21:39:55 +00:00
|
|
|
# for PuTTY
|
|
|
|
# https://github.com/fish-shell/fish-shell/issues/180
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \e\[1~ beginning-of-line
|
|
|
|
bind --preset $argv \e\[3~ delete-char
|
|
|
|
bind --preset $argv \e\[4~ end-of-line
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2020-03-15 19:59:49 +00:00
|
|
|
bind --preset $argv -k home beginning-of-line
|
|
|
|
bind --preset $argv -k end end-of-line
|
2021-10-07 02:24:36 +00:00
|
|
|
bind --preset $argv -k sdc backward-delete-char # shifted delete
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \ca beginning-of-line
|
|
|
|
bind --preset $argv \ce end-of-line
|
|
|
|
bind --preset $argv \ch backward-delete-char
|
|
|
|
bind --preset $argv \cp up-or-search
|
|
|
|
bind --preset $argv \cn down-or-search
|
|
|
|
bind --preset $argv \cf forward-char
|
|
|
|
bind --preset $argv \cb backward-char
|
|
|
|
bind --preset $argv \ct transpose-chars
|
2020-02-04 11:47:44 +00:00
|
|
|
bind --preset $argv \c_ undo
|
2020-06-29 19:31:29 +00:00
|
|
|
bind --preset $argv \cz undo
|
2020-02-04 11:47:44 +00:00
|
|
|
bind --preset $argv \e/ redo
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \et transpose-words
|
|
|
|
bind --preset $argv \eu upcase-word
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2016-11-13 21:39:55 +00:00
|
|
|
# This clashes with __fish_list_current_token
|
2018-09-18 09:52:25 +00:00
|
|
|
# bind --preset $argv \el downcase-word
|
|
|
|
bind --preset $argv \ec capitalize-word
|
2018-05-04 10:14:49 +00:00
|
|
|
# One of these is alt+backspace.
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \e\x7f backward-kill-word
|
|
|
|
bind --preset $argv \e\b backward-kill-word
|
2021-07-23 17:38:43 +00:00
|
|
|
if not test "$TERM_PROGRAM" = Apple_Terminal
|
|
|
|
bind --preset $argv \eb backward-word
|
|
|
|
bind --preset $argv \ef forward-word
|
|
|
|
else
|
|
|
|
# Terminal.app sends \eb for alt+left, \ef for alt+right.
|
|
|
|
# Yeah.
|
|
|
|
bind --preset $argv \eb prevd-or-backward-word
|
|
|
|
bind --preset $argv \ef nextd-or-forward-word
|
|
|
|
end
|
|
|
|
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \e\< beginning-of-buffer
|
|
|
|
bind --preset $argv \e\> end-of-buffer
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \ed kill-word
|
2016-05-25 11:09:33 +00:00
|
|
|
|
2020-09-30 15:25:38 +00:00
|
|
|
# Let ctrl+r search history if there is something in the commandline.
|
|
|
|
bind --preset $argv \cr 'commandline | string length -q; and commandline -f history-search-backward'
|
|
|
|
|
2016-11-13 21:39:55 +00:00
|
|
|
# term-specific special bindings
|
|
|
|
switch "$TERM"
|
2021-11-23 03:55:15 +00:00
|
|
|
case st-256color
|
2021-10-22 21:21:25 +00:00
|
|
|
# suckless and bash/zsh/fish have a different approach to how the terminal should be configured;
|
|
|
|
# the major effect is that several keys do not work as intended.
|
|
|
|
# This is a workaround, there will be additions in he future.
|
2021-10-14 13:50:12 +00:00
|
|
|
bind --preset $argv \e\[P delete-char
|
2021-10-22 21:21:25 +00:00
|
|
|
bind --preset $argv \e\[Z up-line
|
2016-11-13 21:39:55 +00:00
|
|
|
case 'rxvt*'
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \e\[8~ end-of-line
|
|
|
|
bind --preset $argv \eOc forward-word
|
|
|
|
bind --preset $argv \eOd backward-word
|
2020-03-09 18:36:12 +00:00
|
|
|
case xterm-256color
|
2018-03-10 16:57:32 +00:00
|
|
|
# Microsoft's conemu uses xterm-256color plus
|
|
|
|
# the following to tell a console to paste:
|
2018-09-18 09:52:25 +00:00
|
|
|
bind --preset $argv \e\x20ep fish_clipboard_paste
|
2016-11-13 21:39:55 +00:00
|
|
|
end
|
2016-04-17 03:03:14 +00:00
|
|
|
end
|