From 5f849d02646b60943557b00b51a0e592c2387959 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Wed, 13 Apr 2016 19:46:18 -0700 Subject: [PATCH] provide a better experience when user presses \cC Fixes #2904 --- share/functions/__fish_cancel_commandline.fish | 13 +++++++++++++ share/functions/fish_default_key_bindings.fish | 2 +- share/functions/fish_vi_key_bindings.fish | 10 ++++------ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 share/functions/__fish_cancel_commandline.fish diff --git a/share/functions/__fish_cancel_commandline.fish b/share/functions/__fish_cancel_commandline.fish new file mode 100644 index 000000000..f10be75fd --- /dev/null +++ b/share/functions/__fish_cancel_commandline.fish @@ -0,0 +1,13 @@ +# This is meant to be bound to something like \cC. +function __fish_cancel_commandline + set -l cmd (commandline) + if test -n "$cmd" + commandline -C 1000000 + echo (set_color -b bryellow black)"^C"(set_color normal) + for i in (seq (commandline -L)) + echo "" + end + commandline "" + commandline -f repaint + end +end diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index 8d86c7eec..0f0d578cb 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -109,7 +109,7 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis bind $argv \el __fish_list_current_token bind $argv \ew 'set tok (commandline -pt); if test $tok[1]; echo; whatis $tok[1]; commandline -f repaint; end' bind $argv \cl 'clear; commandline -f repaint' - bind $argv \cc 'commandline ""' + bind $argv \cc __fish_cancel_commandline bind $argv \cu backward-kill-line bind $argv \cw backward-kill-path-component bind $argv \ed 'set -l cmd (commandline); if test -z "$cmd"; echo; dirh; commandline -f repaint; else; commandline -f kill-word; end' diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index f63956677..b1fc26594 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -22,22 +22,20 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' # Remove the default self-insert bindings in default mode bind -e "" -M default # Add way to kill current command line while in insert mode. - bind -M insert \cc 'commandline ""' + bind -M insert \cc __fish_cancel_commandline # Add a way to switch from insert to normal (command) mode. bind -M insert -m default \e backward-char force-repaint - # - # normal (command) mode - # + # Default (command) mode bind :q exit bind \cd exit - bind \cc 'commandline ""' + bind -m insert \cc __fish_cancel_commandline bind h backward-char bind l forward-char bind \e\[C forward-char bind \e\[D backward-char - # Some linux VTs output these (why?) + # Some terminals output these when they're in in keypad mode. bind \eOC forward-char bind \eOD backward-char