fzf

From ArchWiki
Jump to navigation Jump to search

fzf is a general-purpose command-line fuzzy finder.

Installation

Install the fzf package. The development version is fzf-gitAUR.

Configuration

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: It should be at least mentioned that shell completer is not the only usecase which requires configuration. (Discuss in Talk:Fzf#)

Shells

Optional fzf keybindings and completion are available for various shells:

  • <CTRL+T> list files+folders in current directory (e.g., git commit <CTRL+T>, select a few files using <TAB>, finally <Return>)
  • <CTRL+R> search history of shell commands
  • <ALT+C> fuzzy change directory

bash

Source the desired files from your .bashrc:

  • /usr/share/fzf/key-bindings.bash
  • /usr/share/fzf/completion.bash

zsh

Source the desired files from your .zshrc (after vi-mode, if using that, too):

  • /usr/share/fzf/key-bindings.zsh
  • /usr/share/fzf/completion.zsh

fish

For fish, keybindings are in:

  • /usr/share/fish/functions/fzf_key_bindings.fish

fish will source this by default but the bindings have to be enabled manually:

~/.config/fish/functions/fish_user_key_bindings.fish
function fish_user_key_bindings
	fzf_key_bindings
end

fzf completion in fish can be enabled with custom functions: https://github.com/junegunn/fzf/wiki/Examples-(fish)

Vim

The basic Vim plugin is already included within the package and installed to Vim's global plugin directory. Thus, you don't need to add anything to your .vimrc to be able to use it. It only provides the FZF command, though. There is an additional Vim plugin made by the author of fzf that defines some convenience functions, see https://github.com/junegunn/fzf.vim.

Arch specific fzf uses

Pacman

Try this to fuzzy-search through all available packages, with package info shown in a preview window, and then install selected packages:

pacman -Slq | fzf -m --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S

If you want to add package file list in preview - may be a bit slower updating preview window (make sure you run pacman -Fy at least once before invocation to sync the pacman file database):

pacman -Slq | fzf -m --preview 'cat <(pacman -Si {1}) <(pacman -Fl {1} | awk "{print \$2}")' | xargs -ro sudo pacman -S

Yay

Same like above, but use yay to also fuzzy-search through the AUR, preview info and install selected packages:

yay -Slq | fzf -m --preview 'yay -Si {1}'| xargs -ro yay -S


Vice versa, you can also use fzf and yay to list all packages on your system, fuzzy-search them and then remove them:

yay -Qeq | fzf -m --preview 'yay -Qi {1}' | xargs -ro yay -Rs

Note that yay -Rs removes the package and all its dependencies as far as they are not required by any other package on your system. To simply remove the selected package only, use yay -R in the snippet above.