10

Is it possible to trigger fzf history search automatically in zsh shell?

In this video, the user clicks "Ctrl+r" to start the history search and then starts typing. Is it possible to start the history search automatically when I start typing anything? Alternatively, is it possible to configure zsh so that a new prompt always starts in the "Ctrl+r" mode?

1

2 Answers 2

9

This is described in the original GitHub repository. In case you are using homebrew you'll just need to type $(brew --prefix)/opt/fzf/install and configure it the way you like. The script will create two files and ask you to update your shell configuration files. For all other installation procedures (git clone, linux brew, ...) have a look at https://github.com/junegunn/fzf

$(brew --prefix)/opt/fzf/install                                                                             ─╯
Downloading bin/fzf ...
  - Already exists
  - Checking fzf executable ... 0.18.0
Do you want to enable fuzzy auto-completion? ([y]/n) y
Do you want to enable key bindings? ([y]/n) y

Generate /Users/hans/.fzf.bash ... OK
Generate /Users/hans/.fzf.zsh ... OK

Do you want to update your shell configuration files? ([y]/n) y

Update /Users/hans/.bashrc:
  - [ -f ~/.fzf.bash ] && source ~/.fzf.bash
    + Added

Update /Users/hans/.zshrc:
  - [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
    + Added

Finished. Restart your shell or reload config file.
   source ~/.bashrc  # bash
   source ~/.zshrc   # zsh

Use uninstall script to remove fzf.
1
  • 3
    OP asked (emphasis mine) "Is it possible to start the history search automatically when I start typing anything?" Your answer does not do that. Nov 5, 2021 at 19:06
4

You cannot start Fzf automatically when you type something. Else, you wouldn’t be able to ever return to your command line, since Fzf would then intercept all of your keystrokes.

However, my zsh-autocomplete plugin can be configured to automatically show matching history items, without leaving the command line. Install the plugin and, additionally, add this setting to your .zshrc file:

zstyle ':autocomplete:*' default-context history-incremental-search-backward

history autocompletion screen recording

Press CtrlR to toggle between history and completions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .