Patrick Connors
Patrick Connors

Reputation: 6065

Bind "up arrow" key to fzf command

I want to use the fzf fuzzyfinder command history instead of the typical command history when I press the up arrow.

In my fzf shell keybindings file I'm able to edit which key brings up the fuzzy finder by editing the following snippet:

bindkey '{command such as ^R}' fzf-history-widget

How can I represent the up arrow key so that it calls this function when pressed? Do I have to disable other functionality somewhere else as well?

Upvotes: 5

Views: 3279

Answers (2)

M Imam Pratama
M Imam Pratama

Reputation: 1279

In bash version 4 or more, none of these works for me:

bind -m emacs-standard -x '"\C-p": __fzf_history__'
bind -m vi-command -x '"\C-p": __fzf_history__'
bind -m vi-insert -x '"\C-p": __fzf_history__'

This also doesn't work:

bind '"\C-p": __fzf_history__'

But this one does the trick for me:

bind -x '"\C-p": __fzf_history__'

By the way, you can use bind -X to see the current binding.

Upvotes: 2

Yasen
Yasen

Reputation: 4474

Binding <Up> key in zsh

Use

bindkey "${key[Up]}" fzf-history-widget

or

bindkey '^[[A' fzf-history-widget

or

bindkey "${terminfo[kcuu1]}" up-line-or-history

to bind <Up> key in zsh to fzf-history-widget function.

Binding <Up> key in bash

You can set the <Up> arrow key to show the commands from history beginning with the characters before the cursor on the command line

bind '"\e[A": history-search-backward'

fzf bindings for bash

There is an issue #1492: [bash] Fire command directly with CTRL-X in CTRL-R

Accordingly, history-exec.bash plugin created for the purpose of history expansion using fzf

macOS Specific Binding

bindkey "${terminfo[kcuu1]}" fzf-history-widget

Upvotes: 7

Related Questions