Skip to content
Myr

README.md

This file

Path

README.md

1,153 lines · 40.8 KiB · Markdown

Last changed by

Update READMEJunegunn Choibefore adoption845752f

History of this file

Take it

Show it rendered

1<div align="center">2  <img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-color.png" alt="fzf - a command-line fuzzy finder">3  <a href="https://github.com/junegunn/fzf/actions"><img src="https://github.com/junegunn/fzf/actions/workflows/linux.yml/badge.svg?branch=master" alt="Build Status"></a>4  <a href="http://github.com/junegunn/fzf/releases"><img src="https://img.shields.io/github/v/tag/junegunn/fzf" alt="Version"></a>5  <a href="https://github.com/junegunn/fzf?tab=MIT-1-ov-file#readme"><img src="https://img.shields.io/github/license/junegunn/fzf" alt="License"></a>6  <a href="https://github.com/junegunn/fzf/graphs/contributors"><img src="https://img.shields.io/github/contributors/junegunn/fzf" alt="Contributors"></a>7  <a href="https://github.com/sponsors/junegunn"><img src="https://img.shields.io/github/sponsors/junegunn" alt="Sponsors"></a>8  <a href="https://github.com/junegunn/fzf/stargazers"><img src="https://img.shields.io/github/stars/junegunn/fzf?style=flat" alt="Stars"></a>9</div>1011---1213<kbd align="center">14  <br/>15  <a href="https://commitgoods.com/collections/fzf"><img src="https://junegunn.github.io/fzf/images/fzf-mugs.jpg" width="80%" alt="fzf merch"></a>16  <br/>17  <br/>18  Show your love for fzf -- T-shirts, mugs, and stickers now available!19  <br/>20  <br/>21  <a href="https://commitgoods.com/collections/fzf">commitgoods.com/collections/fzf</a>22  <br/>23  <br/>24</kbd>2526---2728fzf is a general-purpose command-line fuzzy finder and an interactive terminal toolkit.2930<img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-preview.png" width=640>3132Whether you're selecting files, browsing command history, previewing data,33navigating complex datasets with fuzzy matching, or creating custom menus and34workflows, fzf provides the building blocks to turn shell scripts into rich35terminal applications.3637Highlights38----------3940- **Portable** // Distributed as a single binary for easy installation41- **Fast** // Optimized to process millions of items in milliseconds42- **Programmable** // Event-driven architecture for building custom terminal interfaces and workflows43- **Batteries-included** // Comes with integrations for Bash, Zsh, Fish, Nushell, Vim, and Neovim4445Table of Contents46-----------------4748<!-- vim-markdown-toc GFM -->4950* [Installation](#installation)51    * [Using Homebrew](#using-homebrew)52    * [Using Mise](#using-mise)53    * [Linux packages](#linux-packages)54    * [Windows packages](#windows-packages)55    * [Using git](#using-git)56    * [Binary releases](#binary-releases)57    * [Setting up shell integration](#setting-up-shell-integration)58    * [Vim/Neovim plugin](#vimneovim-plugin)59* [Upgrading fzf](#upgrading-fzf)60* [Building fzf](#building-fzf)61* [Usage](#usage)62    * [Using the finder](#using-the-finder)63    * [Display modes](#display-modes)64        * [`--height` mode](#--height-mode)65        * [`--popup` mode](#--popup-mode)66    * [Search syntax](#search-syntax)67    * [Environment variables](#environment-variables)68    * [Customizing the look](#customizing-the-look)69    * [Options](#options)70    * [Demo](#demo)71* [Examples](#examples)72* [Key bindings for command-line](#key-bindings-for-command-line)73* [Fuzzy completion](#fuzzy-completion)74    * [Files and directories](#files-and-directories)75    * [Process IDs](#process-ids)76    * [Host names](#host-names)77    * [Environment variables / Aliases](#environment-variables--aliases)78    * [Customizing fuzzy completion for bash and zsh](#customizing-fuzzy-completion-for-bash-and-zsh)79        * [Customizing fzf options for completion](#customizing-fzf-options-for-completion)80        * [Customizing completion source for paths and directories](#customizing-completion-source-for-paths-and-directories)81        * [Supported commands (bash)](#supported-commands-bash)82        * [Custom fuzzy completion](#custom-fuzzy-completion)83    * [Fuzzy completion for fish](#fuzzy-completion-for-fish)84    * [Fuzzy completion for Nushell](#fuzzy-completion-for-nushell)85* [Vim plugin](#vim-plugin)86* [Advanced topics](#advanced-topics)87    * [Customizing for different types of input](#customizing-for-different-types-of-input)88    * [Performance](#performance)89    * [Executing external programs](#executing-external-programs)90    * [Turning into a different process](#turning-into-a-different-process)91    * [Reloading the candidate list](#reloading-the-candidate-list)92        * [1. Update the list of processes by pressing CTRL-R](#1-update-the-list-of-processes-by-pressing-ctrl-r)93        * [2. Switch between sources by pressing CTRL-D or CTRL-F](#2-switch-between-sources-by-pressing-ctrl-d-or-ctrl-f)94        * [3. Interactive ripgrep integration](#3-interactive-ripgrep-integration)95    * [Preview window](#preview-window)96    * [Previewing an image](#previewing-an-image)97* [Tips](#tips)98    * [Respecting `.gitignore`](#respecting-gitignore)99    * [Fish shell](#fish-shell)100    * [fzf Theme Playground](#fzf-theme-playground)101* [Related projects](#related-projects)102* [License](#license)103* [Goods](#goods)104* [Sponsors :heart:](#sponsors-heart)105106<!-- vim-markdown-toc -->107108Installation109------------110111### Using Homebrew112113You can use [Homebrew](https://brew.sh/) (on macOS or Linux) to install fzf.114115```sh116brew install fzf117```118119> [!IMPORTANT]120> To set up shell integration (key bindings and fuzzy completion),121> see [the instructions below](#setting-up-shell-integration).122123fzf is also available [via MacPorts][portfile]: `sudo port install fzf`124125[portfile]: https://github.com/macports/macports-ports/blob/master/sysutils/fzf/Portfile126127### Using Mise128129You can use [mise](https://github.com/jdx/mise) to install fzf.130131```sh132mise use -g fzf@latest133```134135### Linux packages136137| Package Manager | Linux Distribution      | Command                            |138| --------------- | ----------------------- | ---------------------------------- |139| APK             | Alpine Linux            | `sudo apk add fzf`                 |140| APT             | Debian 9+/Ubuntu 19.10+ | `sudo apt install fzf`             |141| Conda           |                         | `conda install -c conda-forge fzf` |142| DNF             | Fedora                  | `sudo dnf install fzf`             |143| Nix             | NixOS, etc.             | `nix-env -iA nixpkgs.fzf`          |144| Pacman          | Arch Linux              | `sudo pacman -S fzf`               |145| pkg             | FreeBSD                 | `pkg install fzf`                  |146| pkgin           | NetBSD                  | `pkgin install fzf`                |147| pkg_add         | OpenBSD                 | `pkg_add fzf`                      |148| Portage         | Gentoo                  | `emerge --ask app-shells/fzf`      |149| Spack           |                         | `spack install fzf`                |150| XBPS            | Void Linux              | `sudo xbps-install -S fzf`         |151| Zypper          | openSUSE                | `sudo zypper install fzf`          |152153> [!IMPORTANT]154> To set up shell integration (key bindings and fuzzy completion),155> see [the instructions below](#setting-up-shell-integration).156157[![Packaging status](https://repology.org/badge/vertical-allrepos/fzf.svg?columns=3)](https://repology.org/project/fzf/versions)158159### Windows packages160161On Windows, fzf is available via [Chocolatey][choco], [Scoop][scoop],162[Winget][winget], and [MSYS2][msys2]:163164| Package manager | Command                               |165| --------------- | ------------------------------------- |166| Chocolatey      | `choco install fzf`                   |167| Scoop           | `scoop install fzf`                   |168| Winget          | `winget install fzf`                  |169| MSYS2 (pacman)  | `pacman -S $MINGW_PACKAGE_PREFIX-fzf` |170171[choco]: https://chocolatey.org/packages/fzf172[scoop]: https://github.com/ScoopInstaller/Main/blob/master/bucket/fzf.json173[winget]: https://github.com/microsoft/winget-pkgs/tree/master/manifests/j/junegunn/fzf174[msys2]: https://packages.msys2.org/base/mingw-w64-fzf175176### Using git177178Alternatively, you can "git clone" this repository to any directory and run179[install](https://github.com/junegunn/fzf/blob/master/install) script.180181```sh182git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf183~/.fzf/install184```185186The install script will add lines to your shell configuration file to modify187`$PATH` and set up shell integration.188189### Binary releases190191You can download the official fzf binaries from the releases page.192193* https://github.com/junegunn/fzf/releases194195### Setting up shell integration196197Add the following line to your shell configuration file.198199* bash200  ```sh201  # Set up fzf key bindings and fuzzy completion202  eval "$(fzf --bash)"203  ```204* zsh205  ```sh206  # Set up fzf key bindings and fuzzy completion207  source <(fzf --zsh)208  ```209* fish210  ```fish211  # Set up fzf key bindings212  fzf --fish | source213  ```214* Nushell -- Nushell does not support piping into `source`, so the install215  script generates a file in the autoload directory. If you didn't use the216  install script, you can manually set it up:217  ```nu218  # Generate the integration script219  mkdir ($nu.default-config-dir | path join "autoload")220  fzf --nushell | save -f ($nu.default-config-dir | path join "autoload" "_fzf_integration.nu")221  ```222223> [!NOTE]224> `--bash`, `--zsh`, `--fish`, and `--nushell` options are only available in225> recent versions of fzf. If you have an older version of fzf, or want finer control, you can226> source individual script files in the [/shell](/shell) directory. The227> location of the files may vary depending on the package manager you use.228> Please refer to the package documentation for more information.229> (e.g. `apt show fzf`)230231> [!TIP]232> You can disable CTRL-T, CTRL-R, or ALT-C bindings by setting the233> corresponding `*_COMMAND` variable to an empty string when sourcing the234> script. For example, to disable CTRL-R and ALT-C:235>236> * bash: `FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --bash)"`237> * zsh: `FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source <(fzf --zsh)`238> * fish: `fzf --fish | FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source`239> * nushell: add to your `env.nu`:240>   `$env.FZF_CTRL_R_COMMAND = ""; $env.FZF_ALT_C_COMMAND = ""`241>242> Setting the variables after sourcing the script will have no effect.243244### Vim/Neovim plugin245246If you use [vim-plug](https://github.com/junegunn/vim-plug), add this to247your Vim configuration file:248249```vim250Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }251Plug 'junegunn/fzf.vim'252```253254* `junegunn/fzf` provides the basic library functions255    * `fzf#install()` makes sure that you have the latest binary256* `junegunn/fzf.vim` is [a separate project](https://github.com/junegunn/fzf.vim)257  that provides a variety of useful commands258259To learn more about the Vim integration, see [README-VIM.md](README-VIM.md).260261> [!TIP]262> If you use Neovim and prefer Lua-based plugins, check out263> [fzf-lua](https://github.com/ibhagwan/fzf-lua).264265Upgrading fzf266-------------267268fzf is being actively developed, and you might want to upgrade it once in a269while. Please follow the instruction below depending on the installation270method used.271272- git: `cd ~/.fzf && git pull && ./install`273- brew: `brew update; brew upgrade fzf`274- macports: `sudo port upgrade fzf`275- chocolatey: `choco upgrade fzf`276- vim-plug: `:PlugUpdate fzf`277278Building fzf279------------280281See [BUILD.md](BUILD.md).282283Usage284-----285286fzf will launch interactive finder, read the list from STDIN, and write the287selected item to STDOUT.288289```sh290find * -type f | fzf > selected291```292293Without STDIN pipe, fzf will traverse the file system under the current294directory to get the list of files.295296```sh297vim $(fzf)298```299300> [!NOTE]301> You can override the default behavior302> * Either by setting `$FZF_DEFAULT_COMMAND` to a command that generates the desired list303> * Or by setting `--walker`, `--walker-root`, and `--walker-skip` options in `$FZF_DEFAULT_OPTS`304305> [!WARNING]306> A more robust solution would be to use `xargs` but we've presented307> the above as it's easier to grasp308> ```sh309> fzf --print0 | xargs -0 -o vim310> ```311312> [!TIP]313> fzf also has the ability to turn itself into a different process.314>315> ```sh316> fzf --bind 'enter:become(vim {})'317> ```318>319> *See [Turning into a different process](#turning-into-a-different-process)320> for more information.*321322### Using the finder323324- `CTRL-K` / `CTRL-J` (or `CTRL-P` / `CTRL-N`) to move cursor up and down325- `Enter` key to select the item, `CTRL-C` / `CTRL-G` / `ESC` to exit326- On multi-select mode (`-m`), `TAB` and `Shift-TAB` to mark multiple items327- Emacs style key bindings328- Mouse: scroll, click, double-click; shift-click and shift-scroll on329  multi-select mode330331### Display modes332333fzf by default runs in fullscreen mode, but there are other display modes.334335#### `--height` mode336337With `--height HEIGHT[%]`, fzf will start below the cursor with the given height.338339```sh340fzf --height 40%341```342343`reverse` layout and `--border` goes well with this option.344345```sh346fzf --height 40% --layout reverse --border347```348349By prepending `~` to the height, you're setting the maximum height.350351```sh352# Will take as few lines as possible to display the list353seq 3 | fzf --height ~100%354seq 3000 | fzf --height ~100%355```356357Height value can be a negative number.358359```sh360# Screen height - 3361fzf --height -3362```363364#### `--popup` mode365366With `--popup` option, fzf will start in a popup window367(requires tmux 3.3+ or Zellij 0.44+).368369```sh370# --popup [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]]371372fzf --popup center         # Center, 50% width and height373fzf --popup 80%            # Center, 80% width and height374fzf --popup 100%,50%       # Center, 100% width and 50% height375fzf --popup left,40%       # Left, 40% width376fzf --popup left,40%,90%   # Left, 40% width, 90% height377fzf --popup top,40%        # Top, 40% height378fzf --popup bottom,80%,40% # Bottom, 80% width, 40% height379```380381`--popup` is silently ignored when you're not on tmux or Zellij.382383> [!NOTE]384> If you're stuck with an old version of tmux that doesn't support popup,385> or if you want to open fzf in a regular tmux pane, check out386> [fzf-tmux](bin/fzf-tmux) script.387388> [!TIP]389> You can add these options to `$FZF_DEFAULT_OPTS` so that they're applied by390> default. For example,391>392> ```sh393> # Open in a popup if on tmux or Zellij, otherwise use --height mode394> export FZF_DEFAULT_OPTS='--height 40% --popup bottom,40% --layout reverse --border top'395> ```396397### Search syntax398399Unless otherwise specified, fzf starts in "extended-search mode" where you can400type in multiple search terms delimited by spaces. e.g. `^music .mp3$ sbtrkt401!fire`402403| Token     | Match type                              | Description                                  |404| --------- | --------------------------------------  | ------------------------------------------   |405| `sbtrkt`  | fuzzy-match                             | Items that match `sbtrkt`                    |406| `'wild`   | exact-match (quoted)                    | Items that include `wild`                    |407| `'wild'`  | exact-boundary-match (quoted both ends) | Items that include `wild` at word boundaries |408| `^music`  | prefix-exact-match                      | Items that start with `music`                |409| `.mp3$`   | suffix-exact-match                      | Items that end with `.mp3`                   |410| `!fire`   | inverse-exact-match                     | Items that do not include `fire`             |411| `!^music` | inverse-prefix-exact-match              | Items that do not start with `music`         |412| `!.mp3$`  | inverse-suffix-exact-match              | Items that do not end with `.mp3`            |413414If you don't prefer fuzzy matching and do not wish to "quote" every word,415start fzf with `-e` or `--exact` option. Note that when  `--exact` is set,416`'`-prefix "unquotes" the term.417418A single bar character term acts as an OR operator. For example, the following419query matches entries that start with `core` and end with either `go`, `rb`,420or `py`.421422```423^core go$ | rb$ | py$424```425426### Environment variables427428- `FZF_DEFAULT_COMMAND`429    - Default command to use when input is tty430    - e.g. `export FZF_DEFAULT_COMMAND='fd --type f'`431- `FZF_DEFAULT_OPTS`432    - Default options433    - e.g. `export FZF_DEFAULT_OPTS="--layout=reverse --inline-info"`434- `FZF_DEFAULT_OPTS_FILE`435    - If you prefer to manage default options in a file, set this variable to436      point to the location of the file437    - e.g. `export FZF_DEFAULT_OPTS_FILE=~/.fzfrc`438439> [!WARNING]440> `FZF_DEFAULT_COMMAND` is not used by shell integration due to the441> slight difference in requirements.442>443> * `CTRL-T` runs `$FZF_CTRL_T_COMMAND` to get a list of files and directories444> * `ALT-C` runs `$FZF_ALT_C_COMMAND` to get a list of directories445> * `vim ~/**<tab>` runs `fzf_compgen_path()` with the prefix (`~/`) as the first argument446> * `cd foo**<tab>` runs `fzf_compgen_dir()` with the prefix (`foo`) as the first argument447>448> The available options are described later in this document.449450### Customizing the look451452The user interface of fzf is fully customizable with a large number of453configuration options. For a quick setup, you can start with one of the style454presets -- `default`, `full`, or `minimal` -- using the `--style` option.455456```sh457fzf --style full \458    --preview 'fzf-preview.sh {}' --bind 'focus:transform-header:file --brief {}'459```460461| Preset    | Screenshot                                                                             |462| :---      | :---                                                                                   |463| `default` | <img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-style-default.png"/> |464| `full`    | <img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-style-full.png"/>    |465| `minimal` | <img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-style-minimal.png"/> |466467Here's an example based on the `full` preset:468469<img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-4-borders.png"/>470471<details>472473```sh474git ls-files | fzf --style full \475    --border --padding 1,2 \476    --border-label ' Demo ' --input-label ' Input ' --header-label ' File Type ' \477    --preview 'fzf-preview.sh {}' \478    --bind 'result:transform-list-label:479        if [[ -z $FZF_QUERY ]]; then480          echo " $FZF_MATCH_COUNT items "481        else482          echo " $FZF_MATCH_COUNT matches for [$FZF_QUERY] "483        fi484        ' \485    --bind 'focus:transform-preview-label:[[ -n {} ]] && printf " Previewing [%s] " {}' \486    --bind 'focus:+transform-header:file --brief {} || echo "No file selected"' \487    --bind 'ctrl-r:change-list-label( Reloading the list )+reload(sleep 2; git ls-files)' \488    --color 'border:#aaaaaa,label:#cccccc' \489    --color 'preview-border:#9999cc,preview-label:#ccccff' \490    --color 'list-border:#669966,list-label:#99cc99' \491    --color 'input-border:#996666,input-label:#ffcccc' \492    --color 'header-border:#6699cc,header-label:#99ccff'493```494495</details>496497### Options498499See the man page (`fzf --man` or `man fzf`) for the full list of options.500501### Demo502If you learn by watching videos, check out this screencast by [@samoshkin](https://github.com/samoshkin) to explore `fzf` features.503504<a title="fzf - command-line fuzzy finder" href="https://www.youtube.com/watch?v=qgG5Jhi_Els">505  <img src="https://i.imgur.com/vtG8olE.png" width="640">506</a>507508Examples509--------510511* [Wiki page of examples](https://github.com/junegunn/fzf/wiki/examples)512    * *Disclaimer: The examples on this page are maintained by the community513      and are not thoroughly tested*514* [Advanced fzf examples](https://github.com/junegunn/fzf/blob/master/ADVANCED.md)515516Key bindings for command-line517-----------------------------518519By [setting up shell integration](#setting-up-shell-integration), you can use520the following key bindings in bash, zsh, fish, and Nushell.521522- `CTRL-T` - Paste the selected files and directories onto the command-line523    - The list is generated using `--walker file,dir,follow,hidden` option524        - You can override the behavior by setting `FZF_CTRL_T_COMMAND` to a custom command that generates the desired list525        - Or you can set `--walker*` options in `FZF_CTRL_T_OPTS`526    - Set `FZF_CTRL_T_OPTS` to pass additional options to fzf527      ```sh528      # Preview file content using bat (https://github.com/sharkdp/bat)529      export FZF_CTRL_T_OPTS="530        --walker-skip .git,node_modules,target531        --preview 'bat -n --color=always {}'532        --bind 'ctrl-/:change-preview-window(down|hidden|)'"533      ```534    - Can be disabled by setting `FZF_CTRL_T_COMMAND` to an empty string when535      sourcing the script536- `CTRL-R` - Paste the selected command from history onto the command-line.537    - Select multiple commands with `TAB`.538    - If you want to see the commands in chronological order, press `CTRL-R`539      again which toggles sorting by relevance540    - Press `ALT-R` to toggle "raw" mode where you can see the surrounding items541      of a match. In this mode, you can press `CTRL-N` and `CTRL-P` to move542      between the matching items only.543    - Press `CTRL-/` or `ALT-/` to toggle line wrapping544    - Press `SHIFT-DELETE` to delete the selected commands (bash and fish)545    - Fish shell only:546      - Press `ALT-ENTER` to reformat and insert the selected commands547      - Press `ALT-T` to cycle through command prefix (timestamp, date/time, none)548    - Set `FZF_CTRL_R_OPTS` to pass additional options to fzf549      ```sh550      # CTRL-Y to copy the command into clipboard using pbcopy551      export FZF_CTRL_R_OPTS="552        --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'553        --color header:italic554        --header 'Press CTRL-Y to copy command into clipboard'"555      ```556      ```fish557      # Fish shell: Set date/time as default prefix558      set -gx FZF_CTRL_R_OPTS "--with-nth 1,3.. --bind 'alt-t:change-with-nth(2..|3..|1,3..)'"559560      # Or display no prefix by default561      set -gx FZF_CTRL_R_OPTS "--with-nth 3.. --bind 'alt-t:change-with-nth(2..|1,3..|3..)'"562      ```563    - Can be disabled by setting `FZF_CTRL_R_COMMAND` to an empty string when564      sourcing the script565    - Custom override via a non-empty `FZF_CTRL_R_COMMAND` is not yet supported and will emit a warning566- `ALT-C` - cd into the selected directory567    - The list is generated using `--walker dir,follow,hidden` option568    - Set `FZF_ALT_C_COMMAND` to override the default command569        - Or you can set `--walker-*` options in `FZF_ALT_C_OPTS`570    - Set `FZF_ALT_C_OPTS` to pass additional options to fzf571      ```sh572      # Print tree structure in the preview window573      export FZF_ALT_C_OPTS="574        --walker-skip .git,node_modules,target575        --preview 'tree -C {}'"576      ```577    - Can be disabled by setting `FZF_ALT_C_COMMAND` to an empty string when578      sourcing the script579580Display modes for these bindings can be separately configured via581`FZF_{CTRL_T,CTRL_R,ALT_C}_OPTS` or globally via `FZF_DEFAULT_OPTS`.582(e.g. `FZF_CTRL_R_OPTS='--popup bottom,60% --height 60% --border top'`)583584More tips can be found on [the wiki page](https://github.com/junegunn/fzf/wiki/Configuring-shell-key-bindings).585586Fuzzy completion587----------------588589Shell integration also provides fuzzy completion for bash, zsh, fish, and Nushell.590591### Files and directories592593Fuzzy completion for files and directories can be triggered if the word before594the cursor ends with the trigger sequence, which is by default `**`.595596- `COMMAND [DIRECTORY/][FUZZY_PATTERN]**<TAB>`597598```sh599# Files under the current directory600# - You can select multiple items with TAB key601vim **<TAB>602603# Files under parent directory604vim ../**<TAB>605606# Files under parent directory that match `fzf`607vim ../fzf**<TAB>608609# Files under your home directory610vim ~/**<TAB>611612613# Directories under current directory (single-selection)614cd **<TAB>615616# Directories under ~/github that match `fzf`617cd ~/github/fzf**<TAB>618```619620### Process IDs621622Fuzzy completion for PIDs is provided for kill command.623624```sh625# Can select multiple processes with <TAB> or <Shift-TAB> keys626kill -9 **<TAB>627```628629### Host names630631For ssh command, fuzzy completion for hostnames is provided. The names are632extracted from /etc/hosts and ~/.ssh/config.633634```sh635ssh **<TAB>636```637638### Environment variables / Aliases639640```sh641# bash and zsh642unset **<TAB>643export **<TAB>644unalias **<TAB>645646# fish647set <SHIFT-TAB>648```649650### Customizing fuzzy completion for bash and zsh651652#### Customizing fzf options for completion653654```sh655# Use ~~ as the trigger sequence instead of the default **656export FZF_COMPLETION_TRIGGER='~~'657658# Options to fzf command659export FZF_COMPLETION_OPTS='--border --info=inline'660661# Options for path completion (e.g. vim **<TAB>)662export FZF_COMPLETION_PATH_OPTS='--walker file,dir,follow,hidden'663664# Options for directory completion (e.g. cd **<TAB>)665export FZF_COMPLETION_DIR_OPTS='--walker dir,follow'666667# Advanced customization of fzf options via _fzf_comprun function668# - The first argument to the function is the name of the command.669# - You should make sure to pass the rest of the arguments ($@) to fzf.670_fzf_comprun() {671  local command=$1672  shift673674  case "$command" in675    cd)           fzf --preview 'tree -C {} | head -200'   "$@" ;;676    export|unset) fzf --preview "eval 'echo \$'{}"         "$@" ;;677    ssh)          fzf --preview 'dig {}'                   "$@" ;;678    *)            fzf --preview 'bat -n --color=always {}' "$@" ;;679  esac680}681```682683#### Customizing completion source for paths and directories684685```sh686# Use fd (https://github.com/sharkdp/fd) for listing path candidates.687# - The first argument to the function ($1) is the base path to start traversal688# - See the source code (completion.{bash,zsh}) for the details.689_fzf_compgen_path() {690  fd --hidden --follow --exclude ".git" . "$1"691}692693# Use fd to generate the list for directory completion694_fzf_compgen_dir() {695  fd --type d --hidden --follow --exclude ".git" . "$1"696}697```698699#### Supported commands (bash)700701On bash, fuzzy completion is enabled only for a predefined set of commands702(`complete | grep _fzf` to see the list). But you can enable it for other703commands as well by using `_fzf_setup_completion` helper function.704705```sh706# usage: _fzf_setup_completion path|dir|var|alias|host COMMANDS...707_fzf_setup_completion path ag git kubectl708_fzf_setup_completion dir tree709```710711#### Custom fuzzy completion712713_**(Custom completion API is experimental and subject to change)**_714715For a command named _"COMMAND"_, define `_fzf_complete_COMMAND` function using716`_fzf_complete` helper.717718```sh719# Custom fuzzy completion for "doge" command720#   e.g. doge **<TAB>721_fzf_complete_doge() {722  _fzf_complete --multi --reverse --prompt="doge> " -- "$@" < <(723    echo very724    echo wow725    echo such726    echo doge727  )728}729```730731- The arguments before `--` are the options to fzf.732- After `--`, simply pass the original completion arguments unchanged (`"$@"`).733- Then, write a set of commands that generates the completion candidates and734  feed its output to the function using process substitution (`< <(...)`).735736zsh will automatically pick up the function using the naming convention but in737bash you have to manually associate the function with the command using the738`complete` command.739740```sh741[ -n "$BASH" ] && complete -F _fzf_complete_doge -o default -o bashdefault doge742```743744If you need to post-process the output from fzf, define745`_fzf_complete_COMMAND_post` as follows.746747```sh748_fzf_complete_foo() {749  _fzf_complete --multi --reverse --header-lines=3 -- "$@" < <(750    ls -al751  )752}753754_fzf_complete_foo_post() {755  awk '{print $NF}'756}757758[ -n "$BASH" ] && complete -F _fzf_complete_foo -o default -o bashdefault foo759```760761### Fuzzy completion for fish762763Fuzzy completion for fish differs from bash and zsh in that:764765- It doesn't require a trigger sequence like `**`. Instead, if activates766  on `Shift-TAB` (replacing the native pager search mode), while `TAB` preserves767  fish's native completion behavior.768- It relies on fish's native completion system to populate the candidate list,769  rather than performing a recursive file system traversal. For recursive770  searching, use the `CTRL-T` binding instead.771- If the current command line token is a wildcard pattern, it performs search on772  the wildcard expansion path list (instead of the native behavior of inserting773  all the results in command line). Because the shell is used for the expansion,774  there is a limit in the number of results.775- The only supported configuration variables are `FZF_COMPLETION_OPTS` and776  `FZF_EXPANSION_OPS`.777- The function that is used by custom completion functions is named778  `fzf_complete`, which only accepts fzf options as arguments, and can be also779  called without any redirected input, to just modify fzf options while780  presenting the native completion results. For compatibility with other shells,781  a function named `_fzf_complete` is provided, that can accept ` -- $argv` in782  its command line arguments, after fzf options.783784For commands that are not covered by fish completions, it is better to create785regular fish completion functions (which will work for both `TAB` and786`Shift-TAB`), and create fzf completion functions only when needing to modify787fzf options for a specific command or want different results for `Shift-TAB`:788789```fish790# Customize git completion791function _fzf_complete_git792  # Show header text with active branch for all git completions793  set -lx -- FZF_COMPLETION_OPTS --header="'"(git branch --show-current 2>/dev/null)"'"794795  # No other changes when less than 3 arguments, or when completing options796  if not set -q argv[3]; or string match -q -- '-*' $argv[-1]797    fzf_complete798    return799  end800801  # Check subcommand802  switch $argv[2]803    case checkout diff log show804      # Set preview and display all branches and commits for subcommands: checkout, diff, log, show805      begin806        git branch --all --format='%(refname:short)'807        git log --all --oneline --color=always808      end | fzf_complete --no-multi --ansi --accept-nth=1 --query=$argv[-1] --preview='git show --color=always {1}'809810    case add rm mv811      # Only set preview for subcommands: add, rm, mv812      # Special characters in fish completion lists are escaped, so the r flag must be used.813      fzf_complete --preview="git diff --color=always {r1}"814815    case '*'816      # No changes for other subcommands817      fzf_complete818  end819end820```821822Similar to bash and zsh, the output of fzf can be processed before inserted in823command line, by defining a function named `_fzf_complete_COMMAND_post` or824`_fzf_post_complete_COMMAND`:825826```fish827function _fzf_complete_foo828  ls -sh --zero --color=always | fzf_complete --read0 --print0 --ansi --no-multi-line --header-lines=1829end830831function _fzf_post_complete_foo832  while read -lz result833    string escape -n -- $result | string trim -l -c '\ ' | string split -m 1 -f 2 ' '834  end835end836```837838### Fuzzy completion for Nushell839840Fuzzy completion in Nushell works via the841[external completer](https://www.nushell.sh/cookbook/external_completers.html)842mechanism. There are some differences compared to bash and zsh:843844- On Nushell >= 0.103.0, the external completer is no longer called for845  built-in commands (e.g. `cd`, `ls`). Fuzzy completion with `**<TAB>` only846  works for external commands.847- Custom completers can be defined via the `$env.FZF_COMPLETERS` record in848  your `config.nu`. Each entry is a closure that receives the prefix and the849  command spans, and returns either a list of candidate strings or a record850  `{ candidates: [...], opts: [...] }` for custom fzf options:851  ```nu852  $env.FZF_COMPLETERS = {853      pacman: {|prefix, spans|854          let sub = $spans | skip 1 | first855          let candidates = (if ($sub =~ "-[SF]") { ^pacman -Slq | lines856          } else if ($sub =~ "-[QR]") { ^pacman -Qq | lines857          } else { [] })858          { candidates: $candidates, opts: ["--preview", "pacman -Si {}"] }859      }860  }861  ```862  See [shell/completion-examples.nu](shell/completion-examples.nu) for more863  examples.864- The following environment variables are supported:865  `FZF_COMPLETION_TRIGGER`, `FZF_COMPLETION_OPTS`,866  `FZF_COMPLETION_PATH_OPTS`, `FZF_COMPLETION_DIR_OPTS`,867  `FZF_COMPLETION_DIR_COMMANDS`.868869Vim plugin870----------871872See [README-VIM.md](README-VIM.md).873874Advanced topics875---------------876877### Customizing for different types of input878879Since fzf is a general-purpose text filter, its algorithm was designed to880"generally" work well with any kind of input. However, admittedly, there is no881true one-size-fits-all solution, and you may want to tweak the algorithm and882some of the settings depending on the type of the input. To make this process883easier, fzf provides a set of "scheme"s for some common input types.884885| Scheme             | Description                                                                         |886| :---               | :---                                                                                |887| `--scheme=default` | Generic scheme designed to work well with any kind of input                         |888| `--scheme=path`    | Suitable for file paths                                                             |889| `--scheme=history` | Suitable for command history or any input where chronological ordering is important |890891(See `fzf --man` for the details)892893### Performance894895fzf is fast. Performance should not be a problem in most use cases. However,896you might want to be aware of the options that can affect performance.897898- `--ansi` tells fzf to extract and parse ANSI color codes in the input, and it899  makes the initial scanning slower. So it's not recommended that you add it900  to your `$FZF_DEFAULT_OPTS`.901- `--nth` makes fzf slower because it has to tokenize each line.902- A plain string `--delimiter` should be preferred over a regular expression903  delimiter.904- `--with-nth` makes fzf slower as fzf has to tokenize and reassemble each905  line.906907### Executing external programs908909You can set up key bindings for starting external processes without leaving910fzf (`execute`, `execute-silent`).911912```bash913# Press F1 to open the file with less without leaving fzf914# Press CTRL-Y to copy the line to clipboard and aborts fzf (requires pbcopy)915fzf --bind 'f1:execute(less -f {}),ctrl-y:execute-silent(echo {} | pbcopy)+abort'916```917918See *KEY/EVENT BINDINGS* section of the man page for details.919920### Turning into a different process921922`become(...)` is similar to `execute(...)`/`execute-silent(...)` described923above, but instead of executing the command and coming back to fzf on924complete, it turns fzf into a new process for the command.925926```sh927fzf --bind 'enter:become(vim {})'928```929930Compared to the seemingly equivalent command substitution `vim "$(fzf)"`, this931approach has several advantages:932933* Vim will not open an empty file when you terminate fzf with934  <kbd>CTRL-C</kbd>935* Vim will not open an empty file when you press <kbd>ENTER</kbd> on an empty936  result937* Can handle multiple selections even when they have whitespaces938  ```sh939  fzf --multi --bind 'enter:become(vim {+})'940  ```941942To be fair, running `fzf --print0 | xargs -0 -o vim` instead of `vim "$(fzf)"`943resolves all of the issues mentioned. Nonetheless, `become(...)` still offers944additional benefits in different scenarios.945946* You can set up multiple bindings to handle the result in different ways947  without any wrapping script948  ```sh949  fzf --bind 'enter:become(vim {}),ctrl-e:become(emacs {})'950  ```951  * Previously, you would have to use `--expect=ctrl-e` and check the first952    line of the output of fzf953* You can easily build the subsequent command using the field index954  expressions of fzf955  ```sh956  # Open the file in Vim and go to the line957  git grep --line-number . |958      fzf --delimiter : --nth 3.. --bind 'enter:become(vim {1} +{2})'959  ```960961### Reloading the candidate list962963By binding `reload` action to a key or an event, you can make fzf dynamically964reload the candidate list. See https://github.com/junegunn/fzf/issues/1750 for965more details.966967#### 1. Update the list of processes by pressing CTRL-R968969```sh970ps -ef |971  fzf --bind 'ctrl-r:reload(ps -ef)' \972      --header 'Press CTRL-R to reload' --header-lines=1 \973      --height=50% --layout=reverse974```975976#### 2. Switch between sources by pressing CTRL-D or CTRL-F977978```sh979FZF_DEFAULT_COMMAND='find . -type f' \980  fzf --bind 'ctrl-d:reload(find . -type d),ctrl-f:reload(eval "$FZF_DEFAULT_COMMAND")' \981      --height=50% --layout=reverse982```983984#### 3. Interactive ripgrep integration985986The following example uses fzf as the selector interface for ripgrep. We bound987`reload` action to `change` event, so every time you type on fzf, the ripgrep988process will restart with the updated query string denoted by the placeholder989expression `{q}`. Also, note that we used `--disabled` option so that fzf990doesn't perform any secondary filtering.991992```sh993: | rg_prefix='rg --column --line-number --no-heading --color=always --smart-case' \994    fzf --bind 'start:reload:$rg_prefix ""' \995        --bind 'change:reload:$rg_prefix {q} || true' \996        --bind 'enter:become(vim {1} +{2})' \997        --ansi --disabled \998        --height=50% --layout=reverse999```10001001If ripgrep doesn't find any matches, it will exit with a non-zero exit status,1002and fzf will warn you about it. To suppress the warning message, we added1003`|| true` to the command, so that it always exits with 0.10041005See ["Using fzf as interactive Ripgrep launcher"](https://github.com/junegunn/fzf/blob/master/ADVANCED.md#using-fzf-as-interactive-ripgrep-launcher)1006for more sophisticated examples.10071008### Preview window10091010When the `--preview` option is set, fzf automatically starts an external process1011with the current line as the argument and shows the result in the split window.1012Your `$SHELL` is used to execute the command with `$SHELL -c COMMAND`.1013The window can be scrolled using the mouse or custom key bindings.10141015```bash1016# {} is replaced with the single-quoted string of the focused line1017fzf --preview 'cat {}'1018```10191020Preview window supports ANSI colors, so you can use any program that1021syntax-highlights the content of a file, such as1022[Bat](https://github.com/sharkdp/bat) or1023[Highlight](https://gitlab.com/saalen/highlight):10241025```bash1026fzf --preview 'bat --color=always {}' --preview-window '~3'1027```10281029You can customize the size, position, and border of the preview window using1030`--preview-window` option, and the foreground and background color of it with1031`--color` option. For example,10321033```bash1034fzf --height 40% --layout reverse --info inline --border \1035    --preview 'file {}' --preview-window up,1,border-horizontal \1036    --bind 'ctrl-/:change-preview-window(50%|hidden|)' \1037    --color 'fg:#bbccdd,fg+:#ddeeff,bg:#334455,preview-bg:#223344,border:#778899'1038```10391040See the man page (`man fzf`) for the full list of options.10411042More advanced examples can be found [here](https://github.com/junegunn/fzf/blob/master/ADVANCED.md).10431044> [!WARNING]1045> Since fzf is a general-purpose text filter rather than a file finder, **it is1046> not a good idea to add `--preview` option to your `$FZF_DEFAULT_OPTS`**.1047>1048> ```sh1049> # *********************1050> # ** DO NOT DO THIS! **1051> # *********************1052> export FZF_DEFAULT_OPTS='--preview "bat --style=numbers --color=always --line-range :500 {}"'1053>1054> # bat doesn't work with any input other than the list of files1055> ps -ef | fzf1056> seq 100 | fzf1057> history | fzf1058> ```10591060### Previewing an image10611062fzf can display images in the preview window using one of the following protocols:10631064* [Kitty graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/)1065* [iTerm2 inline images protocol](https://iterm2.com/documentation-images.html)1066* [Sixel](https://en.wikipedia.org/wiki/Sixel)10671068See [bin/fzf-preview.sh](bin/fzf-preview.sh) script for more information.10691070```sh1071fzf --preview 'fzf-preview.sh {}'1072```10731074Tips1075----10761077### Respecting `.gitignore`10781079You can use [fd](https://github.com/sharkdp/fd),1080[ripgrep](https://github.com/BurntSushi/ripgrep), or [the silver1081searcher](https://github.com/ggreer/the_silver_searcher) to traverse the file1082system while respecting `.gitignore`.10831084```sh1085# Feed the output of fd into fzf1086fd --type f --strip-cwd-prefix | fzf10871088# Setting fd as the default source for fzf1089export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix'10901091# Now fzf (w/o pipe) will use the fd command to generate the list1092fzf10931094# To apply the command to CTRL-T as well1095export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"1096```10971098If you want the command to follow symbolic links and don't want it to exclude1099hidden files, use the following command:11001101```sh1102export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix --hidden --follow --exclude .git'1103```11041105### Fish shell11061107`CTRL-T` key binding of fish, unlike those of bash and zsh, will use the last1108token on the command-line as the root directory for the recursive search. For1109instance, hitting `CTRL-T` at the end of the following command-line11101111```sh1112ls /var/1113```11141115will list all files and directories under `/var/`.11161117When using a custom `FZF_CTRL_T_COMMAND`, use the unexpanded `$dir` variable to1118make use of this feature. `$dir` defaults to `.` when the last token is not a1119valid directory. Example:11201121```sh1122set -g FZF_CTRL_T_COMMAND "command find -L \$dir -type f 2> /dev/null | sed '1d; s#^\./##'"1123```11241125### fzf Theme Playground11261127[fzf Theme Playground](https://vitormv.github.io/fzf-themes/) created by1128[Vitor Mello](https://github.com/vitormv) is a webpage where you can1129interactively create fzf themes.11301131Related projects1132----------------11331134https://github.com/junegunn/fzf/wiki/Related-projects11351136[License](LICENSE)1137------------------11381139The MIT License (MIT)11401141Copyright (c) 2013-2026 Junegunn Choi11421143Goods1144-----11451146Grab fzf T-shirts, mugs, and stickers here: https://commitgoods.com/collections/fzf11471148Sponsors :heart:1149----------------11501151I would like to thank all the sponsors of this project who make it possible for me to continue to improve fzf.11521153If you'd like to sponsor this project, please visit https://github.com/sponsors/junegunn.