2022-01-28 08:21:22 +08:00
|
|
|
function fish_default_key_bindings -d "emacs-like key binds"
|
2024-03-30 23:10:12 +08:00
|
|
|
set -l legacy_bind bind
|
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
|
2020-03-10 02:36:12 +08:00
|
|
|
if test "$fish_key_bindings" != fish_default_key_bindings
|
2024-10-26 04:47:20 +08:00
|
|
|
__fish_change_key_bindings fish_default_key_bindings || return
|
|
|
|
set fish_bind_mode default
|
2016-11-14 05:39:55 +08:00
|
|
|
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
|
2020-03-10 02:36:12 +08:00
|
|
|
set argv -s $argv
|
2017-10-03 16:29:48 +08:00
|
|
|
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
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-k kill-line
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv right forward-char
|
|
|
|
bind --preset $argv left backward-char
|
|
|
|
$legacy_bind --preset $argv -k right forward-char
|
|
|
|
$legacy_bind --preset $argv -k left backward-char
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv delete delete-char
|
|
|
|
bind --preset $argv backspace backward-delete-char
|
|
|
|
bind --preset $argv shift-backspace backward-delete-char
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv home beginning-of-line
|
|
|
|
$legacy_bind --preset $argv -k home beginning-of-line
|
|
|
|
bind --preset $argv end end-of-line
|
|
|
|
$legacy_bind --preset $argv -k end end-of-line
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-a beginning-of-line
|
|
|
|
bind --preset $argv ctrl-e end-of-line
|
|
|
|
bind --preset $argv ctrl-h backward-delete-char
|
|
|
|
bind --preset $argv ctrl-p up-or-search
|
|
|
|
bind --preset $argv ctrl-n down-or-search
|
|
|
|
bind --preset $argv ctrl-f forward-char
|
|
|
|
bind --preset $argv ctrl-b backward-char
|
|
|
|
bind --preset $argv ctrl-t transpose-chars
|
|
|
|
bind --preset $argv ctrl-g cancel
|
|
|
|
bind --preset $argv ctrl-/ undo
|
|
|
|
bind --preset $argv ctrl-_ undo # XTerm idiosyncracy, can get rid of this once we go full CSI u
|
|
|
|
bind --preset $argv ctrl-z undo
|
2024-04-19 18:34:15 +08:00
|
|
|
bind --preset $argv ctrl-Z redo
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-/ redo
|
|
|
|
bind --preset $argv alt-t transpose-words
|
|
|
|
bind --preset $argv alt-u upcase-word
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-c capitalize-word
|
Default bindings for token movement commands
There is no natural default binding for token movements. Add the
alt-{left,right,backspace,delete}, breaking some existing behavior.
For example, backward-delete-word is no longer bound to alt-backspace but
only to ctrl-backspace. Unfortunately some terminals (particularly tmux)
don't support distinguishing ctrl-backspace from ctrl-h yet, so the loss
of alt-backspace may be tragic.
---
I guess we could also add:
bind alt-B backward-token
bind alt-F forward-token
bind ctrl-W backward-kill-token
bind alt-D kill-token
Those might be intercepted by the terminal on Linux, but I don't know where
that happens.
Tested on foot, kitty, alacritty, xterm, tmux, konsole and gnome-terminal.
Closes #10766
2024-10-06 03:44:29 +08:00
|
|
|
bind --preset $argv alt-backspace backward-kill-token
|
2024-09-23 20:28:04 +08:00
|
|
|
bind --preset $argv ctrl-backspace backward-kill-word
|
Default bindings for token movement commands
There is no natural default binding for token movements. Add the
alt-{left,right,backspace,delete}, breaking some existing behavior.
For example, backward-delete-word is no longer bound to alt-backspace but
only to ctrl-backspace. Unfortunately some terminals (particularly tmux)
don't support distinguishing ctrl-backspace from ctrl-h yet, so the loss
of alt-backspace may be tragic.
---
I guess we could also add:
bind alt-B backward-token
bind alt-F forward-token
bind ctrl-W backward-kill-token
bind alt-D kill-token
Those might be intercepted by the terminal on Linux, but I don't know where
that happens.
Tested on foot, kitty, alacritty, xterm, tmux, konsole and gnome-terminal.
Closes #10766
2024-10-06 03:44:29 +08:00
|
|
|
bind --preset $argv alt-delete kill-token
|
2024-09-23 20:42:46 +08:00
|
|
|
bind --preset $argv ctrl-delete kill-word
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-b backward-word
|
|
|
|
bind --preset $argv alt-f forward-word
|
|
|
|
if test "$TERM_PROGRAM" = Apple_Terminal
|
2021-07-24 01:38:43 +08:00
|
|
|
# Terminal.app sends \eb for alt+left, \ef for alt+right.
|
|
|
|
# Yeah.
|
2024-03-30 23:10:12 +08:00
|
|
|
$legacy_bind --preset $argv alt-b prevd-or-backward-word
|
|
|
|
$legacy_bind --preset $argv alt-f nextd-or-forward-word
|
2021-07-24 01:38:43 +08:00
|
|
|
end
|
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-\< beginning-of-buffer
|
|
|
|
bind --preset $argv alt-\> end-of-buffer
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-r history-pager
|
2020-09-30 23:25:38 +08:00
|
|
|
|
2016-11-14 05:39:55 +08:00
|
|
|
# term-specific special bindings
|
|
|
|
switch "$TERM"
|
2021-11-23 11:55:15 +08:00
|
|
|
case st-256color
|
2021-10-23 05:21:25 +08: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.
|
2024-03-30 23:10:12 +08:00
|
|
|
$legacy_bind --preset $argv \e\[P delete-char
|
|
|
|
$legacy_bind --preset $argv \e\[Z up-line
|
2020-03-10 02:36:12 +08:00
|
|
|
case xterm-256color
|
2018-03-11 00:57:32 +08:00
|
|
|
# Microsoft's conemu uses xterm-256color plus
|
|
|
|
# the following to tell a console to paste:
|
2024-03-30 23:10:12 +08:00
|
|
|
$legacy_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
|