Skip to content

Commit

Permalink
Modify CTRL-R behavior to execute on Enter
Browse files Browse the repository at this point in the history
If you want to edit the command before execution, press Ctrl-E instead
of Enter when selecting the entry.

Taken from: junegunn#477
  • Loading branch information
vedang committed Aug 15, 2020
1 parent e2ae1b2 commit 40e6679
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion shell/key-bindings.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40e6679

Please # to comment.