fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
cb1de5aab
master
1# localization: skip(private) 2function __fish_shared_key_bindings -d"Prints function body for bindings shared between emacs and vi mode" 3# These are some bindings that are supposed to be shared between vi mode and default mode. 4# They are supposed to be unrelated to text-editing (or movement). 5# This takes $argv so the vi-bindings can pass the mode they are valid in. 6# The code is printed instead of executed so that `bind` attributes the bindings to the caller. 7printf %s' 8if contains -- -h $argv 9or contains -- --help $argv 10echo "Sorry but this function doesn\'t support -h or --help" >&2 11return 1 12end 13bind --preset $argv ctrl-y yank 14or return # protect against invalid $argv 15bind --preset $argv alt-y yank-pop 16 17# Left/Right arrow 18bind --preset $argv right forward-char 19bind --preset $argv left backward-char 20 21# Ctrl-left/right - these also work in vim. 22bind --preset $argv ctrl-right forward-token 23bind --preset $argv ctrl-left backward-token 24 25bind --preset $argv pageup beginning-of-history 26bind --preset $argv pagedown end-of-history 27 28# Interaction with the system clipboard. 29bind --preset $argv ctrl-x fish_clipboard_copy 30bind --preset $argv ctrl-v fish_clipboard_paste 31 32bind --preset $argv escape cancel 33bind --preset $argv ctrl-\[ cancel 34bind --preset $argv tab complete 35bind --preset $argv ctrl-i complete 36bind --preset $argv ctrl-s pager-toggle-search 37# shift-tab does a tab complete followed by a search. 38bind --preset $argv shift-tab complete-and-search 39bind --preset $argv shift-delete history-delete or backward-delete-char 40 41bind --preset $argv down down-or-search 42bind --preset $argv up up-or-search 43 44bind --preset $argv shift-right forward-bigword 45bind --preset $argv shift-left backward-bigword 46 47bind --preset $argv alt-b prevd-or-backward-word 48bind --preset $argv alt-f nextd-or-forward-word 49 50for alt_right in alt-right \e\[1\;9C # TODO(terminal-workaround) iTerm2 < 3.5.12 51bind --preset $argv $alt_right nextd-or-forward-word 52end 53for alt_left in alt-left \e\[1\;9D # TODO(terminal-workaround) iTerm2 < 3.5.12 54bind --preset $argv $alt_left prevd-or-backward-word 55end 56 57bind --preset $argv alt-up history-token-search-backward 58bind --preset $argv alt-down history-token-search-forward 59# TODO(terminal-workaround) 60bind --preset $argv \e\[1\;9A history-token-search-backward # iTerm2 < 3.5.12 61bind --preset $argv \e\[1\;9B history-token-search-forward # iTerm2 < 3.5.12 62# Bash compatibility 63# https://github.com/fish-shell/fish-shell/issues/89 64bind --preset $argv alt-. history-token-search-backward 65 66bind --preset $argv alt-l __fish_list_current_token 67bind --preset $argv alt-o __fish_preview_current_file 68bind --preset $argv alt-w __fish_whatis_current_token 69bind --preset $argv ctrl-l \ 70"status test-terminal-feature scroll-content-up && commandline -f scrollback-push" \ 71clear-screen 72bind --preset $argv ctrl-c clear-commandline 73bind --preset $argv ctrl-u backward-kill-line 74bind --preset $argv ctrl-k kill-line 75bind --preset $argv ctrl-w backward-kill-path-component 76bind --preset $argv end end-of-line 77bind --preset $argv home beginning-of-line 78 79bind --preset $argv alt-d \'if test "$(commandline; printf .)" = \n.; __fish_echo dirh; else; commandline -f kill-word; end\' 80bind --preset $argv ctrl-d delete-or-exit 81 82bind --preset $argv alt-s \'for cmd in sudo doas please run0; if command -q $cmd; fish_commandline_prepend $cmd; break; end; end\' 83 84# Allow reading manpages by pressing f1 (many GUI applications) or Alt+h (like in zsh). 85bind --preset $argv f1 __fish_man_page 86bind --preset $argv alt-h __fish_man_page 87 88# This will make sure the output of the current command is paged using the default pager when 89# you press Meta-p. 90# If none is set, less will be used. 91bind --preset $argv alt-p __fish_paginate 92 93# Make it easy to turn an unexecuted command into a comment in the shell history. Also, 94# remove the commenting chars so the command can be further edited then executed. 95bind --preset $argv alt-# __fish_toggle_comment_commandline 96 97# These keystrokes invoke an external editor on the command buffer. 98bind --preset $argv alt-e edit_command_buffer 99bind --preset $argv alt-v edit_command_buffer 100 101# Bindings that are shared in text-insertion modes. 102if not set -l index (contains --index -- -M $argv) 103or test $argv[(math $index + 1)] = insert 104 105# This is the default binding, i.e. the one used if no other binding matches 106bind --preset $argv "" self-insert 107or exit # protect against invalid $argv 108 109# Space and other command terminators expands abbrs _and_ inserts itself. 110bind --preset $argv space self-insert expand-abbr 111bind --preset $argv ";" self-insert expand-abbr 112bind --preset $argv "|" self-insert expand-abbr 113bind --preset $argv "&" self-insert expand-abbr 114bind --preset $argv ">" self-insert expand-abbr 115bind --preset $argv "<" self-insert expand-abbr 116set -l maybe_search_field "(commandline --search-field >/dev/null && echo --search-field)" 117bind --preset $argv shift-enter "commandline -i \n $maybe_search_field" expand-abbr 118bind --preset $argv alt-enter "commandline -i \n $maybe_search_field" expand-abbr 119bind --preset $argv ")" self-insert expand-abbr # Closing a command substitution. 120bind --preset $argv ctrl-space \'test -n "$(commandline)" && commandline -i " " \'$maybe_search_field 121# Shift-space behaves like space because it\'s easy to mistype. 122bind --preset $argv shift-space \'commandline -i " " \'$maybe_search_field expand-abbr 123 124bind --preset $argv enter execute 125bind --preset $argv ctrl-j execute 126bind --preset $argv ctrl-m execute 127# Make Control+Return behave like Return because it\'s easy to mistype after accepting an autosuggestion. 128bind --preset $argv ctrl-enter execute 129end' 130end