fzf is a general-purpose command-line fuzzy finder.
It’s an interactive filter program for any kind of list; files, command
history, processes, hostnames, bookmarks, git commits, etc. It implements
a “fuzzy” matching algorithm, so you can quickly type in patterns with omitted
characters and still get the results you want.
Add the following line to your shell configuration file.
bash
Terminal window
# Set up fzf key bindings and fuzzy completion
eval"$(fzf--bash)"
zsh
Terminal window
# Set up fzf key bindings and fuzzy completion
source<(fzf--zsh)
fish
# Set up fzf key bindings
fzf --fish | source
[!NOTE]
--bash, --zsh, and --fish options are only available in fzf 0.48.0 or
later. If you have an older version of fzf, or want finer control, you can
source individual script files in the [/shell]!(/shell) directory. The
location of the files may vary depending on the package manager you use.
Please refer to the package documentation for more information.
(e.g. apt show fzf)
[!TIP]
You can disable CTRL-T, CTRL-R, or ALT-C bindings by setting the
corresponding *_COMMAND variable to an empty string when sourcing the
script. For example, to disable CTRL-R and ALT-C:
fzf is being actively developed, and you might want to upgrade it once in a
while. Please follow the instruction below depending on the installation
method used.
--tmux is silently ignored when you’re not on tmux.
[!NOTE]
If you’re stuck with an old version of tmux that doesn’t support popup,
or if you want to open fzf in a regular tmux pane, check out
[fzf-tmux]!(bin/fzf-tmux) script.
[!TIP]
You can add these options to $FZF_DEFAULT_OPTS so that they’re applied by
default. For example,
Terminal window
# Open in tmux popup if on tmux, otherwise use --height mode
Unless otherwise specified, fzf starts in “extended-search mode” where you can
type in multiple search terms delimited by spaces. e.g. ^music .mp3$ sbtrkt !fire
Token
Match type
Description
sbtrkt
fuzzy-match
Items that match sbtrkt
'wild
exact-match (quoted)
Items that include wild
'wild'
exact-boundary-match (quoted both ends)
Items that include wild at word boundaries
^music
prefix-exact-match
Items that start with music
.mp3$
suffix-exact-match
Items that end with .mp3
!fire
inverse-exact-match
Items that do not include fire
!^music
inverse-prefix-exact-match
Items that do not start with music
!.mp3$
inverse-suffix-exact-match
Items that do not end with .mp3
If you don’t prefer fuzzy matching and do not wish to “quote” every word,
start fzf with -e or --exact option. Note that when --exact is set,
'-prefix “unquotes” the term.
A single bar character term acts as an OR operator. For example, the following
query matches entries that start with core and end with either go, rb,
or py.
The user interface of fzf is fully customizable with a large number of
configuration options. For a quick setup, you can start with one of the style
presets — default, full, or minimal — using the --style option.
Can be disabled by setting FZF_CTRL_T_COMMAND to an empty string when
sourcing the script
CTRL-R - Paste the selected command from history onto the command-line
If you want to see the commands in chronological order, press CTRL-R
again which toggles sorting by relevance
Press ALT-R to toggle “raw” mode where you can see the surrounding items
of a match. In this mode, you can press CTRL-N and CTRL-P to move
between the matching items only.
Press CTRL-/ or ALT-/ to toggle line wrapping
Set FZF_CTRL_R_OPTS to pass additional options to fzf
Terminal window
# CTRL-Y to copy the command into clipboard using pbcopy
--header 'Press CTRL-Y to copy command into clipboard'"
Can be disabled by setting FZF_CTRL_R_COMMAND to an empty string when
sourcing the script
Custom override via a non-empty FZF_CTRL_R_COMMAND is not yet supported and will emit a warning
ALT-C - cd into the selected directory
The list is generated using --walker dir,follow,hidden option
Set FZF_ALT_C_COMMAND to override the default command
Or you can set --walker-* options in FZF_ALT_C_OPTS
Set FZF_ALT_C_OPTS to pass additional options to fzf
Terminal window
# Print tree structure in the preview window
exportFZF_ALT_C_OPTS="
--walker-skip .git,node_modules,target
--preview 'tree -C {}'"
Can be disabled by setting FZF_ALT_C_COMMAND to an empty string when
sourcing the script
Display modes for these bindings can be separately configured via
FZF_{CTRL_T,CTRL_R,ALT_C}_OPTS or globally via FZF_DEFAULT_OPTS.
(e.g. FZF_CTRL_R_OPTS='--tmux bottom,60% --height 60% --border top')
On bash, fuzzy completion is enabled only for a predefined set of commands
(complete | grep _fzf to see the list). But you can enable it for other
commands as well by using _fzf_setup_completion helper function.
After --, simply pass the original completion arguments unchanged ("$@").
Then, write a set of commands that generates the completion candidates and
feed its output to the function using process substitution (< <(...)).
zsh will automatically pick up the function using the naming convention but in
bash you have to manually associate the function with the command using the
complete command.
Since fzf is a general-purpose text filter, its algorithm was designed to
“generally” work well with any kind of input. However, admittedly, there is no
true one-size-fits-all solution, and you may want to tweak the algorithm and
some of the settings depending on the type of the input. To make this process
easier, fzf provides a set of “scheme”s for some common input types.
Scheme
Description
--scheme=default
Generic scheme designed to work well with any kind of input
--scheme=path
Suitable for file paths
--scheme=history
Suitable for command history or any input where chronological ordering is important
fzf is fast. Performance should not be a problem in most use cases. However,
you might want to be aware of the options that can affect performance.
--ansi tells fzf to extract and parse ANSI color codes in the input, and it
makes the initial scanning slower. So it’s not recommended that you add it
to your $FZF_DEFAULT_OPTS.
--nth makes fzf slower because it has to tokenize each line.
A plain string --delimiter should be preferred over a regular expression
delimiter.
--with-nth makes fzf slower as fzf has to tokenize and reassemble each
line.
become(...) is similar to execute(...)/execute-silent(...) described
above, but instead of executing the command and coming back to fzf on
complete, it turns fzf into a new process for the command.
Terminal window
fzf--bind'enter:become(vim {})'
Compared to the seemingly equivalent command substitution vim "$(fzf)", this
approach has several advantages:
Vim will not open an empty file when you terminate fzf with
CTRL-C
Vim will not open an empty file when you press ENTER on an empty
result
Can handle multiple selections even when they have whitespaces
Terminal window
fzf--multi--bind'enter:become(vim {+})'
To be fair, running fzf --print0 | xargs -0 -o vim instead of vim "$(fzf)"
resolves all of the issues mentioned. Nonetheless, become(...) still offers
additional benefits in different scenarios.
You can set up multiple bindings to handle the result in different ways
without any wrapping script
The following example uses fzf as the selector interface for ripgrep. We bound
reload action to change event, so every time you type on fzf, the ripgrep
process will restart with the updated query string denoted by the placeholder
expression {q}. Also, note that we used --disabled option so that fzf
doesn’t perform any secondary filtering.
If ripgrep doesn’t find any matches, it will exit with a non-zero exit status,
and fzf will warn you about it. To suppress the warning message, we added
|| true to the command, so that it always exits with 0.
When the --preview option is set, fzf automatically starts an external process
with the current line as the argument and shows the result in the split window.
Your $SHELL is used to execute the command with $SHELL -c COMMAND.
The window can be scrolled using the mouse or custom key bindings.
Terminal window
# {} is replaced with the single-quoted string of the focused line
fzf--preview'cat {}'
Preview window supports ANSI colors, so you can use any program that
syntax-highlights the content of a file, such as
Bat or
Highlight:
You can customize the size, position, and border of the preview window using
--preview-window option, and the foreground and background color of it with
--color option. For example,
[!WARNING]
Since fzf is a general-purpose text filter rather than a file finder, it is
not a good idea to add --preview option to your $FZF_DEFAULT_OPTS.
CTRL-T key binding of fish, unlike those of bash and zsh, will use the last
token on the command-line as the root directory for the recursive search. For
instance, hitting CTRL-T at the end of the following command-line
Terminal window
ls/var/
will list all files and directories under /var/.
When using a custom FZF_CTRL_T_COMMAND, use the unexpanded $dir variable to
make use of this feature. $dir defaults to . when the last token is not a
valid directory. Example:
Terminal window
set-gFZF_CTRL_T_COMMAND"command find -L \$dir -type f 2> /dev/null | sed '1d; s#^\./##'"