9

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?

kvs
  • 91
  • 1
  • 1
  • 2
  • Not fzf finder, but alike: https://unix.stackexchange.com/questions/109366/does-bash-have-similar-features-such-as-fishs-autosuggestions-and-highlighting – Xopi García Aug 09 '20 at 23:20

2 Answers2

8

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.
plattenschieber
  • 189
  • 1
  • 2
  • 2
    OP asked (emphasis mine) "Is it possible to start the history search _automatically_ when I start typing _anything?"_ Your answer does not do that. – Marlon Richert Nov 05 '21 at 19:06
3

You cannot start Fzf automatically when you type anything or 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 show matching history items automatically, without leaving the command line, if you 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.

Marlon Richert
  • 3,715
  • 5
  • 30