From 40e6679fed296db20f23fee17cc4190f98d47da7 Mon Sep 17 00:00:00 2001 From: Vedang Manerikar Date: Sat, 15 Aug 2020 18:16:22 +0530 Subject: [PATCH] Modify CTRL-R behavior to execute on Enter If you want to edit the command before execution, press Ctrl-E instead of Enter when selecting the entry. Taken from: https://github.com/junegunn/fzf/issues/477 --- shell/key-bindings.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index 74ce9b71ac6..af0b708f38f 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -101,12 +101,18 @@ fzf-history-widget() { local selected num setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null selected=( $(fc -rl 1 | perl -ne 'print if !$seen{(/^\s*[0-9]+\s+(.*)/, $1)}++' | - FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) ) + FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort --expect=ctrl-e $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) ) local ret=$? if [ -n "$selected" ]; then + local accept=0 + if [[ $selected[1] = ctrl-e ]]; then + accept=1 + shift selected + fi num=$selected[1] if [ -n "$num" ]; then zle vi-fetch-history -n $num + [[ $accept = 0 ]] && zle accept-line fi fi zle reset-prompt