2016-04-15 16:55:39 +08:00
|
|
|
function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fish"
|
2016-11-14 06:07:03 +08: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-14 05:39:55 +08:00
|
|
|
if not set -q argv[1]
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --erase --all --preset # clear earlier bindings, if any
|
2016-11-14 05:39:55 +08:00
|
|
|
if test "$fish_key_bindings" != "fish_default_key_bindings"
|
|
|
|
# Allow the user to set the variable universally
|
|
|
|
set -q fish_key_bindings
|
|
|
|
or set -g fish_key_bindings
|
2016-11-14 06:07:03 +08: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-14 05:39:55 +08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2017-10-03 16:29:48 +08:00
|
|
|
# Silence warnings about unavailable keys. See #4431, 4188
|
|
|
|
if not contains -- -s $argv
|
|
|
|
set argv "-s" $argv
|
|
|
|
end
|
|
|
|
|
2016-05-25 19:09:33 +08:00
|
|
|
# These are shell-specific bindings that we share with vi mode.
|
2016-09-04 05:00:41 +08:00
|
|
|
__fish_shared_key_bindings $argv
|
2016-11-28 13:27:22 +08:00
|
|
|
or return # protect against invalid $argv
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2016-11-14 05:39:55 +08:00
|
|
|
# This is the default binding, i.e. the one used if no other binding matches
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv "" self-insert
|
2016-11-28 13:27:22 +08:00
|
|
|
or exit # protect against invalid $argv
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv \n execute
|
|
|
|
bind --preset $argv \r execute
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv \ck kill-line
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2018-09-18 17:52:25 +08: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 19:09:33 +08:00
|
|
|
|
2018-09-18 17:52:25 +08: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 19:09:33 +08:00
|
|
|
|
2016-11-14 05:39:55 +08:00
|
|
|
# for PuTTY
|
|
|
|
# https://github.com/fish-shell/fish-shell/issues/180
|
2018-09-18 17:52:25 +08: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 19:09:33 +08:00
|
|
|
|
2016-11-14 05:39:55 +08:00
|
|
|
# OS X SnowLeopard doesn't have these keys. Don't show an annoying error message.
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv -k home beginning-of-line 2>/dev/null
|
|
|
|
bind --preset $argv -k end end-of-line 2>/dev/null
|
|
|
|
bind --preset $argv \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-ctrl-delete
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2018-09-18 17:52:25 +08: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
|
|
|
|
bind --preset $argv \et transpose-words
|
|
|
|
bind --preset $argv \eu upcase-word
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2016-11-14 05:39:55 +08:00
|
|
|
# This clashes with __fish_list_current_token
|
2018-09-18 17:52:25 +08:00
|
|
|
# bind --preset $argv \el downcase-word
|
|
|
|
bind --preset $argv \ec capitalize-word
|
2018-05-04 18:14:49 +08:00
|
|
|
# One of these is alt+backspace.
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv \e\x7f backward-kill-word
|
|
|
|
bind --preset $argv \e\b backward-kill-word
|
|
|
|
bind --preset $argv \eb backward-word
|
|
|
|
bind --preset $argv \ef forward-word
|
|
|
|
bind --preset $argv \e\[1\;5C forward-word
|
|
|
|
bind --preset $argv \e\[1\;5D backward-word
|
|
|
|
bind --preset $argv \e\< beginning-of-buffer
|
|
|
|
bind --preset $argv \e\> end-of-buffer
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv \ed kill-word
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2016-11-14 05:39:55 +08:00
|
|
|
# term-specific special bindings
|
|
|
|
switch "$TERM"
|
|
|
|
case 'rxvt*'
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv \e\[8~ end-of-line
|
|
|
|
bind --preset $argv \eOc forward-word
|
|
|
|
bind --preset $argv \eOd backward-word
|
2018-03-11 00:57:32 +08:00
|
|
|
case 'xterm-256color'
|
|
|
|
# Microsoft's conemu uses xterm-256color plus
|
|
|
|
# the following to tell a console to paste:
|
2018-09-18 17:52:25 +08:00
|
|
|
bind --preset $argv \e\x20ep fish_clipboard_paste
|
2016-11-14 05:39:55 +08:00
|
|
|
end
|
2016-04-17 11:03:14 +08:00
|
|
|
end
|