From 44c6fa68cfae06337801da42e273eeee5ef90a67 Mon Sep 17 00:00:00 2001 From: Julian Aron Prenner Date: Mon, 20 Jan 2014 13:07:32 +0100 Subject: [PATCH] Make Ctrl-x autocomplete suggestions; cosmetics --- share/functions/fish_vi_cursor.fish | 106 +++---- share/functions/fish_vi_key_bindings.fish | 341 +++++++++++----------- 2 files changed, 222 insertions(+), 225 deletions(-) diff --git a/share/functions/fish_vi_cursor.fish b/share/functions/fish_vi_cursor.fish index e59d715f8..e3dae47a7 100644 --- a/share/functions/fish_vi_cursor.fish +++ b/share/functions/fish_vi_cursor.fish @@ -1,59 +1,59 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes' - set -l terminal $argv[1] - set -q terminal[1]; or set terminal auto + set -l terminal $argv[1] + set -q terminal[1]; or set terminal auto - switch "$terminal" - case auto - if set -q KONSOLE_PROFILE_NAME - set terminal konsole - else if set -q XTERM_LOCALE - set terminal xterm - else - #echo Not found - return 1 - end - end - - set -l command - set -l start - set -l end - set -l shape_block - set -l shape_line - set -l shape_underline - switch "$terminal" - case konsole iterm - set command echo -en - set start "\e]50;" - set end "\x7" - set shape_block 'CursorShape=0' - set shape_line 'CursorShape=1' - set shape_underline 'CursorShape=2' - case xterm - set command echo -en - set start '\e[' - set end ' q' - set shape_block '2' - set shape_underline '4' - set shape_line '6' - end - if not set -q command[1] - #echo not found + switch "$terminal" + case auto + if set -q KONSOLE_PROFILE_NAME + set terminal konsole + else if set -q XTERM_LOCALE + set terminal xterm + else + #echo Not found return 1 end - set -g fish_cursor_insert $start$shape_line$end - set -g fish_cursor_default $start$shape_block$end - set -g fish_cursor_other $start$shape_block$end + end - echo " - function fish_vi_cursor_handle --on-variable fish_bind_mode - switch \$fish_bind_mode - case insert - $command \$fish_cursor_insert - case default - $command \$fish_cursor_default - case '*' - $command \$fish_cursor_other - end - end - " | source + set -l command + set -l start + set -l end + set -l shape_block + set -l shape_line + set -l shape_underline + switch "$terminal" + case konsole iterm + set command echo -en + set start "\e]50;" + set end "\x7" + set shape_block 'CursorShape=0' + set shape_line 'CursorShape=1' + set shape_underline 'CursorShape=2' + case xterm + set command echo -en + set start '\e[' + set end ' q' + set shape_block '2' + set shape_underline '4' + set shape_line '6' + end + if not set -q command[1] + #echo not found + return 1 + end + set -g fish_cursor_insert $start$shape_line$end + set -g fish_cursor_default $start$shape_block$end + set -g fish_cursor_other $start$shape_block$end + + echo " + function fish_vi_cursor_handle --on-variable fish_bind_mode + switch \$fish_bind_mode + case insert + $command \$fish_cursor_insert + case default + $command \$fish_cursor_default + case '*' + $command \$fish_cursor_other + end + end + " | source end diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index cb6309782..8dc40da51 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -1,214 +1,211 @@ function fish_vi_key_bindings -d "vi-like key bindings for fish" - bind --erase --all + bind --erase --all - ## - ## command mode - ## - #bind -m command : force-repaint - #bind -M command q exit - #bind -M command -m default \e force-repaint - #bind -M command -m default \cc force-repaint + ## + ## command mode + ## - bind :q exit + bind :q exit - # - # normal (default) mode - # + # + # normal (default) mode + # - bind \cd exit - bind h backward-char - bind l forward-char - bind \e\[C forward-char - bind \e\[D backward-char - bind -k right forward-char - bind -k left backward-char - bind \n execute - bind -m insert i force-repaint - bind -m insert I beginning-of-line force-repaint - bind -m insert a forward-char force-repaint - bind -m insert A end-of-line force-repaint - bind -m visual v begin-selection force-repaint + bind \cd exit + bind h backward-char + bind l forward-char + bind \e\[C forward-char + bind \e\[D backward-char + bind -k right forward-char + bind -k left backward-char + bind \n execute + bind -m insert i force-repaint + bind -m insert I beginning-of-line force-repaint + bind -m insert a forward-char force-repaint + bind -m insert A end-of-line force-repaint + bind -m visual v begin-selection force-repaint - #bind -m insert o "commandline -a \n" down-line force-repaint - #bind -m insert O beginning-of-line "commandline -i \n" up-line force-repaint # doesn't work + #bind -m insert o "commandline -a \n" down-line force-repaint + #bind -m insert O beginning-of-line "commandline -i \n" up-line force-repaint # doesn't work - bind gg beginning-of-buffer - bind G end-of-buffer + bind gg beginning-of-buffer + bind G end-of-buffer - bind \x24 end-of-line - bind \x5e beginning-of-line - bind g\x24 end-of-line - bind g\x5e beginning-of-line - bind \e\[H beginning-of-line - bind \e\[F end-of-line + bind \x24 end-of-line + bind \x5e beginning-of-line + bind g\x24 end-of-line + bind g\x5e beginning-of-line + bind \e\[H beginning-of-line + bind \e\[F end-of-line - # NOTE: history-search-backward and history-search-forward - # must both be bound for `commandline -f ...' to work, and thus for up-or-search - # and down-or-search to work, since those are actually - # simple shell functions that use `commandline -f ...'. - # Generally, commandline -f can only invoke functions that have been bound previously + bind u history-search-backward + bind \cr history-search-forward - bind u history-search-backward - bind \cr history-search-forward + bind [ history-token-search-backward + bind ] history-token-search-forward - bind [ history-token-search-backward - bind ] history-token-search-forward + bind k up-or-search + bind j down-or-search + bind \e\[A up-or-search + bind \e\[B down-or-search + bind -k down down-or-search + bind -k up up-or-search - bind k up-or-search - bind j down-or-search - bind \e\[A up-or-search - bind \e\[B down-or-search - bind -k down down-or-search - bind -k up up-or-search + bind b backward-word + bind B backward-word + bind gE backward-word + bind gE backward-word + bind w forward-word + bind W forward-word + bind e forward-word + bind E forward-word - bind b backward-word - bind B backward-word - bind gE backward-word - bind gE backward-word - bind w forward-word - bind W forward-word - bind e forward-word - bind E forward-word + bind x delete-char + bind X backward-delete-char - bind x delete-char - bind X backward-delete-char + bind -k dc delete-char - bind -k dc delete-char + bind -k backspace backward-delete-char + bind \x7f backward-delete-char + bind \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-delete - bind -k backspace backward-delete-char - bind \x7f backward-delete-char - bind \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-delete + bind dd kill-whole-line + bind D kill-line + bind d\x24 kill-line + bind d\x5e backward-kill-line + bind dw kill-word + bind dW kill-word + bind diw forward-char forward-char backward-word kill-word + bind diW forward-char forward-char backward-word kill-word + bind daw forward-char forward-char backward-word kill-word + bind daW forward-char forward-char backward-word kill-word + bind de kill-word + bind dE kill-word + bind db backward-kill-word + bind dB backward-kill-word + bind dgE backward-kill-word + bind dgE backward-kill-word - bind dd kill-whole-line - bind D kill-line - bind d\x24 kill-line - bind d\x5e backward-kill-line - bind dw kill-word - bind dW kill-word - bind diw forward-char forward-char backward-word kill-word - bind diW forward-char forward-char backward-word kill-word - bind daw forward-char forward-char backward-word kill-word - bind daW forward-char forward-char backward-word kill-word - bind de kill-word - bind dE kill-word - bind db backward-kill-word - bind dB backward-kill-word - bind dgE backward-kill-word - bind dgE backward-kill-word + bind -m insert s delete-char force-repaint + bind -m insert S kill-whole-line force-repaint + bind -m insert cc kill-whole-line force-repaint + bind -m insert C kill-line force-repaint + bind -m insert c\x24 kill-line force-repaint + bind -m insert c\x5e backward-kill-line force-repaint + bind -m insert cw kill-word force-repaint + bind -m insert cW kill-word force-repaint + bind -m insert ciw forward-char forward-char backward-word kill-word force-repaint + bind -m insert ciW forward-char forward-char backward-word kill-word force-repaint + bind -m insert caw forward-char forward-char backward-word kill-word force-repaint + bind -m insert caW forward-char forward-char backward-word kill-word force-repaint + bind -m insert ce kill-word force-repaint + bind -m insert cE kill-word force-repaint + bind -m insert cb backward-kill-word force-repaint + bind -m insert cB backward-kill-word force-repaint + bind -m insert cgE backward-kill-word force-repaint + bind -m insert cgE backward-kill-word force-repaint - bind -m insert s delete-char force-repaint - bind -m insert S kill-whole-line force-repaint - bind -m insert cc kill-whole-line force-repaint - bind -m insert C kill-line force-repaint - bind -m insert c\x24 kill-line force-repaint - bind -m insert c\x5e backward-kill-line force-repaint - bind -m insert cw kill-word force-repaint - bind -m insert cW kill-word force-repaint - bind -m insert ciw forward-char forward-char backward-word kill-word force-repaint - bind -m insert ciW forward-char forward-char backward-word kill-word force-repaint - bind -m insert caw forward-char forward-char backward-word kill-word force-repaint - bind -m insert caW forward-char forward-char backward-word kill-word force-repaint - bind -m insert ce kill-word force-repaint - bind -m insert cE kill-word force-repaint - bind -m insert cb backward-kill-word force-repaint - bind -m insert cB backward-kill-word force-repaint - bind -m insert cgE backward-kill-word force-repaint - bind -m insert cgE backward-kill-word force-repaint + bind '~' capitalize-word + bind gu downcase-word + bind gU upcase-word - bind '~' capitalize-word - bind gu downcase-word - bind gU upcase-word + bind J end-of-line delete-char + bind K 'man (commandline -t) ^/dev/null; or echo -n \a' - bind J end-of-line delete-char - bind K 'man (commandline -t) ^/dev/null; or echo -n \a' + bind yy kill-whole-line yank + bind Y kill-whole-line yank + bind y\x24 kill-line yank + bind y\x5e backward-kill-line yank + bind yw kill-word yank + bind yW kill-word yank + bind yiw forward-char forward-char backward-word kill-word yank + bind yiW forward-char forward-char backward-word kill-word yank + bind yaw forward-char forward-char backward-word kill-word yank + bind yaW forward-char forward-char backward-word kill-word yank + bind ye kill-word yank + bind yE kill-word yank + bind yb backward-kill-word yank + bind yB backward-kill-word yank + bind ygE backward-kill-word yank + bind ygE backward-kill-word yank - bind yy kill-whole-line yank - bind Y kill-whole-line yank - bind y\x24 kill-line yank - bind y\x5e backward-kill-line yank - bind yw kill-word yank - bind yW kill-word yank - bind yiw forward-char forward-char backward-word kill-word yank - bind yiW forward-char forward-char backward-word kill-word yank - bind yaw forward-char forward-char backward-word kill-word yank - bind yaW forward-char forward-char backward-word kill-word yank - bind ye kill-word yank - bind yE kill-word yank - bind yb backward-kill-word yank - bind yB backward-kill-word yank - bind ygE backward-kill-word yank - bind ygE backward-kill-word yank + # in emacs yank means paste + bind p yank + bind P backward-char yank + bind gp yank-pop - # in emacs yank means paste - bind p yank - bind P backward-char yank - bind gp yank-pop + bind '"*p' "commandline -i ( xsel -p; echo )[1]" + bind '"*P' backward-char "commandline -i ( xsel -p; echo )[1]" - bind '"*p' "commandline -i ( xsel -p; echo )[1]" - bind '"*P' backward-char "commandline -i ( xsel -p; echo )[1]" + # + # insert mode + # - # - # insert mode - # + bind -M insert "" self-insert + bind -M insert \n execute - bind -M insert "" self-insert - bind -M insert \n execute + bind -M insert -k dc delete-char - bind -M insert -k dc delete-char + bind -M insert -k backspace backward-delete-char + bind -M insert \x7f backward-delete-char + # Mavericks Terminal.app shift-delete + bind -M insert \e\[3\;2~ backward-delete-char - bind -M insert -k backspace backward-delete-char - bind -M insert \x7f backward-delete-char - # Mavericks Terminal.app shift-delete - bind -M insert \e\[3\;2~ backward-delete-char + bind -M insert \t complete - bind -M insert \t complete + # OS X SnowLeopard doesn't have these keys. Don't show an annoying error message. + bind -M insert -k home beginning-of-line 2> /dev/null + bind -M insert -k end end-of-line 2> /dev/null + bind -M insert \e\[3\;2~ backward-delete-char # Mavericks Terminal.app shift-delete - bind -M insert \e\[A up-or-search - bind -M insert \e\[B down-or-search - bind -M insert -k down down-or-search - bind -M insert -k up up-or-search + bind -M insert \cx end-of-line - bind -M insert \e\[C forward-char - bind -M insert \e\[D backward-char - bind -M insert -k right forward-char - bind -M insert -k left backward-char + bind -M insert \e\[A up-or-search + bind -M insert \e\[B down-or-search + bind -M insert -k down down-or-search + bind -M insert -k up up-or-search - bind -M insert -m default \cc force-repaint - bind -M insert -m default \e force-repaint + bind -M insert \e\[C forward-char + bind -M insert \e\[D backward-char + bind -M insert -k right forward-char + bind -M insert -k left backward-char - bind -M insert \cd exit + bind -M insert -m default \cc force-repaint + bind -M insert -m default \e force-repaint - bind -M insert \ef forward-word + bind -M insert \cd exit + + bind -M insert \ef forward-word - # - # visual mode - # + # + # visual mode + # - bind -M visual \e\[C forward-char - bind -M visual \e\[D backward-char - bind -M visual -k right forward-char - bind -M visual -k left backward-char - bind -M visual h backward-char - bind -M visual l forward-char + bind -M visual \e\[C forward-char + bind -M visual \e\[D backward-char + bind -M visual -k right forward-char + bind -M visual -k left backward-char + bind -M visual h backward-char + bind -M visual l forward-char - bind -M visual b backward-word - bind B backward-word - bind gE backward-word - bind gE backward-word - bind w forward-word - bind W forward-word - bind -M visual e forward-word - bind -M visual E forward-word + bind -M visual b backward-word + bind -M visual B backward-word + bind -M visual gE backward-word + bind -M visual gE backward-word + bind -M visual w forward-word + bind -M visual W forward-word + bind -M visual e forward-word + bind -M visual E forward-word - bind -M visual -m default d kill-selection end-selection force-repaint - bind -M visual -m default x kill-selection end-selection force-repaint - bind -M visual -m default X kill-whole-line end-selection force-repaint - bind -M visual -m default y kill-selection yank end-selection force-repaint - bind -M visual -m default '"*y' "commandline -s | xsel -p" end-selection force-repaint + bind -M visual -m default d kill-selection end-selection force-repaint + bind -M visual -m default x kill-selection end-selection force-repaint + bind -M visual -m default X kill-whole-line end-selection force-repaint + bind -M visual -m default y kill-selection yank end-selection force-repaint + bind -M visual -m default '"*y' "commandline -s | xsel -p" end-selection force-repaint - bind -M visual -m default \cc end-selection force-repaint - bind -M visual -m default \e end-selection force-repaint + bind -M visual -m default \cc end-selection force-repaint + bind -M visual -m default \e end-selection force-repaint end