Bind "up arrow" key to fzf command
Asked Answered
S

2

5

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?

Sell answered 5/9, 2019 at 19:33 Comment(1)
thanks for question, I'll try that keybinding for myself too)Gloze
G
7

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

Gloze answered 5/9, 2019 at 19:55 Comment(7)
That's throwing the error: cannot bind to an empty key sequence where a valid setting is bindkey "^R" fzf-history-widget (I am working in zsh)Sell
Which version of zsh do you use? It works for me ( zsh --version : zsh 5.4.2 (x86_64-ubuntu-linux-gnu) )Gloze
I'm zsh 5.7.1 (on macOS)Sell
Try bindkey '^[[A' fzf-history-widget or bindkey "${terminfo[kcuu1]}" up-line-or-historyGloze
No luck there eitherSell
Sorry. Anyway, thanks for your idea to use Up arrowGloze
Actually, briefly got into a state where it worked. Trying to reproduce and then I'll make a not on the answer, but upvoting for now. Thanks for the help!Sell
K
2

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.

Kielty answered 3/11, 2021 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.