2016-05-25 19:09:33 +08:00
|
|
|
function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mode"
|
2024-03-30 23:10:12 +08:00
|
|
|
set -l legacy_bind bind
|
2016-05-25 19:09:33 +08:00
|
|
|
# These are some bindings that are supposed to be shared between vi mode and default mode.
|
|
|
|
# They are supposed to be unrelated to text-editing (or movement).
|
|
|
|
# This takes $argv so the vi-bindings can pass the mode they are valid in.
|
|
|
|
|
2016-11-14 06:07:03 +08:00
|
|
|
if contains -- -h $argv
|
|
|
|
or contains -- --help $argv
|
2022-04-04 11:57:55 +08:00
|
|
|
echo "Sorry but this function doesn't support -h or --help" >&2
|
2016-11-14 06:07:03 +08:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-y yank
|
2016-11-28 13:27:22 +08:00
|
|
|
or return # protect against invalid $argv
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-y yank-pop
|
2016-05-25 19:09:33 +08:00
|
|
|
|
|
|
|
# Left/Right arrow
|
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
|
|
|
|
2020-03-15 19:58:51 +08:00
|
|
|
# Ctrl-left/right - these also work in vim.
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-right forward-word
|
|
|
|
bind --preset $argv ctrl-left backward-word
|
2020-03-15 19:58:51 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv pageup beginning-of-history
|
|
|
|
bind --preset $argv pagedown end-of-history
|
|
|
|
$legacy_bind --preset $argv -k ppage beginning-of-history
|
|
|
|
$legacy_bind --preset $argv -k npage end-of-history
|
2017-01-16 03:11:38 +08:00
|
|
|
|
2016-05-25 19:09:33 +08:00
|
|
|
# Interaction with the system clipboard.
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-x fish_clipboard_copy
|
|
|
|
bind --preset $argv ctrl-v fish_clipboard_paste
|
|
|
|
|
|
|
|
bind --preset $argv escape cancel
|
|
|
|
bind --preset $argv ctrl-\[ cancel
|
|
|
|
bind --preset $argv tab complete
|
|
|
|
bind --preset $argv ctrl-i complete
|
|
|
|
bind --preset $argv ctrl-s pager-toggle-search
|
2016-05-25 19:09:33 +08:00
|
|
|
# shift-tab does a tab complete followed by a search.
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv shift-tab complete-and-search
|
|
|
|
$legacy_bind --preset $argv -k btab complete-and-search
|
|
|
|
bind --preset $argv shift-delete history-pager-delete or backward-delete-char
|
|
|
|
$legacy_bind --preset $argv -k sdc history-pager-delete or backward-delete-char
|
|
|
|
|
|
|
|
bind --preset $argv down down-or-search
|
|
|
|
$legacy_bind --preset $argv -k down down-or-search
|
|
|
|
bind --preset $argv up up-or-search
|
|
|
|
$legacy_bind --preset $argv -k up up-or-search
|
|
|
|
|
|
|
|
bind --preset $argv shift-right forward-bigword
|
|
|
|
bind --preset $argv shift-left backward-bigword
|
|
|
|
$legacy_bind --preset $argv -k sright forward-bigword
|
|
|
|
$legacy_bind --preset $argv -k sleft backward-bigword
|
|
|
|
|
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-right nextd-or-forward-token
|
|
|
|
bind --preset $argv alt-left prevd-or-backward-token
|
2024-03-30 23:10:12 +08:00
|
|
|
|
|
|
|
bind --preset $argv alt-up history-token-search-backward
|
|
|
|
bind --preset $argv alt-down history-token-search-forward
|
2016-05-25 19:09:33 +08:00
|
|
|
# Bash compatibility
|
|
|
|
# https://github.com/fish-shell/fish-shell/issues/89
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-. history-token-search-backward
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-l __fish_list_current_token
|
|
|
|
bind --preset $argv alt-o __fish_preview_current_file
|
|
|
|
bind --preset $argv alt-w __fish_whatis_current_token
|
|
|
|
bind --preset $argv ctrl-l clear-screen
|
|
|
|
bind --preset $argv ctrl-c cancel-commandline
|
|
|
|
bind --preset $argv ctrl-u backward-kill-line
|
|
|
|
bind --preset $argv ctrl-w backward-kill-path-component
|
|
|
|
bind --preset $argv end end-of-line
|
|
|
|
bind --preset $argv home beginning-of-line
|
2016-09-04 01:27:42 +08:00
|
|
|
|
2024-04-23 17:37:53 +08:00
|
|
|
bind --preset $argv alt-d 'if test "$(commandline; printf .)" = \n.; __fish_echo dirh; else; commandline -f kill-word; end'
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-d delete-or-exit
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-s 'for cmd in sudo doas please; if command -q $cmd; fish_commandline_prepend $cmd; break; end; end'
|
2019-09-26 00:34:54 +08:00
|
|
|
|
2024-05-23 04:29:35 +08:00
|
|
|
# Allow reading manpages by pressing f1 (many GUI applications) or Alt+h (like in zsh).
|
|
|
|
bind --preset $argv f1 __fish_man_page
|
2024-03-30 23:10:12 +08:00
|
|
|
$legacy_bind --preset $argv -k f1 __fish_man_page
|
|
|
|
bind --preset $argv alt-h __fish_man_page
|
2016-05-25 19:09:33 +08:00
|
|
|
|
2016-11-14 06:07:03 +08:00
|
|
|
# This will make sure the output of the current command is paged using the default pager when
|
|
|
|
# you press Meta-p.
|
2016-05-25 19:09:33 +08:00
|
|
|
# If none is set, less will be used.
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-p __fish_paginate
|
2016-11-14 06:07:03 +08:00
|
|
|
|
2016-05-25 19:09:33 +08:00
|
|
|
# Make it easy to turn an unexecuted command into a comment in the shell history. Also,
|
|
|
|
# remove the commenting chars so the command can be further edited then executed.
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv alt-# __fish_toggle_comment_commandline
|
2018-03-07 18:06:23 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
# These keystrokes invoke an external editor on the command buffer.
|
|
|
|
bind --preset $argv alt-e edit_command_buffer
|
|
|
|
bind --preset $argv alt-v edit_command_buffer
|
2022-04-25 03:15:36 +08:00
|
|
|
|
|
|
|
# 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.
|
2024-05-03 14:30:27 +08:00
|
|
|
bind --preset $argv space 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 shift-enter "commandline -i \n" expand-abbr
|
|
|
|
bind --preset $argv alt-enter "commandline -i \n" expand-abbr
|
|
|
|
bind --preset $argv ")" self-insert expand-abbr # Closing a command substitution.
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-space 'test -n "$(commandline)" && commandline -i " "'
|
2022-05-12 03:57:37 +08:00
|
|
|
bind --preset $argv -k nul 'test -n "$(commandline)" && commandline -i " "'
|
2024-03-30 23:10:12 +08:00
|
|
|
# Shift-space behaves like space because it's easy to mistype.
|
2024-05-03 14:30:27 +08:00
|
|
|
bind --preset $argv shift-space 'commandline -i " "' expand-abbr
|
2022-04-25 03:15:36 +08:00
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv enter execute
|
|
|
|
bind --preset $argv ctrl-j execute
|
|
|
|
bind --preset $argv ctrl-m execute
|
2022-12-12 01:20:24 +08:00
|
|
|
# Make Control+Return behave like Return because it's easy to mistype after accepting an autosuggestion.
|
2024-03-30 23:10:12 +08:00
|
|
|
bind --preset $argv ctrl-enter execute
|
2017-03-09 23:52:38 +08:00
|
|
|
end
|
|
|
|
end
|