Debian Codegraph @

README.md

raw
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>
10
11 ---
12
13 <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>
25
26 ---
27
28 fzf is a general-purpose command-line fuzzy finder and an interactive terminal toolkit.
29
30 <img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-preview.png" width=640>
31
32 Whether you're selecting files, browsing command history, previewing data,
33 navigating complex datasets with fuzzy matching, or creating custom menus and
34 workflows, fzf provides the building blocks to turn shell scripts into rich
35 terminal applications.
36
37 Highlights
38 ----------
39
40 - **Portable** // Distributed as a single binary for easy installation
41 - **Fast** // Optimized to process millions of items in milliseconds
42 - **Programmable** // Event-driven architecture for building custom terminal interfaces and workflows
43 - **Batteries-included** // Comes with integrations for Bash, Zsh, Fish, Nushell, Vim, and Neovim
44
45 Table of Contents
46 -----------------
47
48 <!-- vim-markdown-toc GFM -->
49
50 * [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)
105
106 <!-- vim-markdown-toc -->
107
108 Installation
109 ------------
110
111 ### Using Homebrew
112
113 You can use [Homebrew](https://brew.sh/) (on macOS or Linux) to install fzf.
114
115 ```sh
116 brew install fzf
117 ```
118
119 > [!IMPORTANT]
120 > To set up shell integration (key bindings and fuzzy completion),
121 > see [the instructions below](#setting-up-shell-integration).
122
123 fzf is also available [via MacPorts][portfile]: `sudo port install fzf`
124
125 [portfile]: https://github.com/macports/macports-ports/blob/master/sysutils/fzf/Portfile
126
127 ### Using Mise
128
129 You can use [mise](https://github.com/jdx/mise) to install fzf.
130
131 ```sh
132 mise use -g fzf@latest
133 ```
134
135 ### Linux packages
136
137 | 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` |
152
153 > [!IMPORTANT]
154 > To set up shell integration (key bindings and fuzzy completion),
155 > see [the instructions below](#setting-up-shell-integration).
156
157 [![Packaging status](https://repology.org/badge/vertical-allrepos/fzf.svg?columns=3)](https://repology.org/project/fzf/versions)
158
159 ### Windows packages
160
161 On Windows, fzf is available via [Chocolatey][choco], [Scoop][scoop],
162 [Winget][winget], and [MSYS2][msys2]:
163
164 | 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` |
170
171 [choco]: https://chocolatey.org/packages/fzf
172 [scoop]: https://github.com/ScoopInstaller/Main/blob/master/bucket/fzf.json
173 [winget]: https://github.com/microsoft/winget-pkgs/tree/master/manifests/j/junegunn/fzf
174 [msys2]: https://packages.msys2.org/base/mingw-w64-fzf
175
176 ### Using git
177
178 Alternatively, you can "git clone" this repository to any directory and run
179 [install](https://github.com/junegunn/fzf/blob/master/install) script.
180
181 ```sh
182 git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
183 ~/.fzf/install
184 ```
185
186 The install script will add lines to your shell configuration file to modify
187 `$PATH` and set up shell integration.
188
189 ### Binary releases
190
191 You can download the official fzf binaries from the releases page.
192
193 * https://github.com/junegunn/fzf/releases
194
195 ### Setting up shell integration
196
197 Add the following line to your shell configuration file.
198
199 * bash
200 ```sh
201 # Set up fzf key bindings and fuzzy completion
202 eval "$(fzf --bash)"
203 ```
204 * zsh
205 ```sh
206 # Set up fzf key bindings and fuzzy completion
207 source <(fzf --zsh)
208 ```
209 * fish
210 ```fish
211 # Set up fzf key bindings
212 fzf --fish | source
213 ```
214 * Nushell -- Nushell does not support piping into `source`, so the install
215 script generates a file in the autoload directory. If you didn't use the
216 install script, you can manually set it up:
217 ```nu
218 # Generate the integration script
219 mkdir ($nu.default-config-dir | path join "autoload")
220 fzf --nushell | save -f ($nu.default-config-dir | path join "autoload" "_fzf_integration.nu")
221 ```
222
223 > [!NOTE]
224 > `--bash`, `--zsh`, `--fish`, and `--nushell` options are only available in
225 > recent versions of fzf. If you have an older version of fzf, or want finer control, you can
226 > source individual script files in the [/shell](/shell) directory. The
227 > 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`)
230
231 > [!TIP]
232 > You can disable CTRL-T, CTRL-R, or ALT-C bindings by setting the
233 > corresponding `*_COMMAND` variable to an empty string when sourcing the
234 > 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.
243
244 ### Vim/Neovim plugin
245
246 If you use [vim-plug](https://github.com/junegunn/vim-plug), add this to
247 your Vim configuration file:
248
249 ```vim
250 Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
251 Plug 'junegunn/fzf.vim'
252 ```
253
254 * `junegunn/fzf` provides the basic library functions
255 * `fzf#install()` makes sure that you have the latest binary
256 * `junegunn/fzf.vim` is [a separate project](https://github.com/junegunn/fzf.vim)
257 that provides a variety of useful commands
258
259 To learn more about the Vim integration, see [README-VIM.md](README-VIM.md).
260
261 > [!TIP]
262 > If you use Neovim and prefer Lua-based plugins, check out
263 > [fzf-lua](https://github.com/ibhagwan/fzf-lua).
264
265 Upgrading fzf
266 -------------
267
268 fzf is being actively developed, and you might want to upgrade it once in a
269 while. Please follow the instruction below depending on the installation
270 method used.
271
272 - 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`
277
278 Building fzf
279 ------------
280
281 See [BUILD.md](BUILD.md).
282
283 Usage
284 -----
285
286 fzf will launch interactive finder, read the list from STDIN, and write the
287 selected item to STDOUT.
288
289 ```sh
290 find * -type f | fzf > selected
291 ```
292
293 Without STDIN pipe, fzf will traverse the file system under the current
294 directory to get the list of files.
295
296 ```sh
297 vim $(fzf)
298 ```
299
300 > [!NOTE]
301 > You can override the default behavior
302 > * Either by setting `$FZF_DEFAULT_COMMAND` to a command that generates the desired list
303 > * Or by setting `--walker`, `--walker-root`, and `--walker-skip` options in `$FZF_DEFAULT_OPTS`
304
305 > [!WARNING]
306 > A more robust solution would be to use `xargs` but we've presented
307 > the above as it's easier to grasp
308 > ```sh
309 > fzf --print0 | xargs -0 -o vim
310 > ```
311
312 > [!TIP]
313 > fzf also has the ability to turn itself into a different process.
314 >
315 > ```sh
316 > fzf --bind 'enter:become(vim {})'
317 > ```
318 >
319 > *See [Turning into a different process](#turning-into-a-different-process)
320 > for more information.*
321
322 ### Using the finder
323
324 - `CTRL-K` / `CTRL-J` (or `CTRL-P` / `CTRL-N`) to move cursor up and down
325 - `Enter` key to select the item, `CTRL-C` / `CTRL-G` / `ESC` to exit
326 - On multi-select mode (`-m`), `TAB` and `Shift-TAB` to mark multiple items
327 - Emacs style key bindings
328 - Mouse: scroll, click, double-click; shift-click and shift-scroll on
329 multi-select mode
330
331 ### Display modes
332
333 fzf by default runs in fullscreen mode, but there are other display modes.
334
335 #### `--height` mode
336
337 With `--height HEIGHT[%]`, fzf will start below the cursor with the given height.
338
339 ```sh
340 fzf --height 40%
341 ```
342
343 `reverse` layout and `--border` goes well with this option.
344
345 ```sh
346 fzf --height 40% --layout reverse --border
347 ```
348
349 By prepending `~` to the height, you're setting the maximum height.
350
351 ```sh
352 # Will take as few lines as possible to display the list
353 seq 3 | fzf --height ~100%
354 seq 3000 | fzf --height ~100%
355 ```
356
357 Height value can be a negative number.
358
359 ```sh
360 # Screen height - 3
361 fzf --height -3
362 ```
363
364 #### `--popup` mode
365
366 With `--popup` option, fzf will start in a popup window
367 (requires tmux 3.3+ or Zellij 0.44+).
368
369 ```sh
370 # --popup [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]]
371
372 fzf --popup center # Center, 50% width and height
373 fzf --popup 80% # Center, 80% width and height
374 fzf --popup 100%,50% # Center, 100% width and 50% height
375 fzf --popup left,40% # Left, 40% width
376 fzf --popup left,40%,90% # Left, 40% width, 90% height
377 fzf --popup top,40% # Top, 40% height
378 fzf --popup bottom,80%,40% # Bottom, 80% width, 40% height
379 ```
380
381 `--popup` is silently ignored when you're not on tmux or Zellij.
382
383 > [!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 out
386 > [fzf-tmux](bin/fzf-tmux) script.
387
388 > [!TIP]
389 > You can add these options to `$FZF_DEFAULT_OPTS` so that they're applied by
390 > default. For example,
391 >
392 > ```sh
393 > # Open in a popup if on tmux or Zellij, otherwise use --height mode
394 > export FZF_DEFAULT_OPTS='--height 40% --popup bottom,40% --layout reverse --border top'
395 > ```
396
397 ### Search syntax
398
399 Unless otherwise specified, fzf starts in "extended-search mode" where you can
400 type in multiple search terms delimited by spaces. e.g. `^music .mp3$ sbtrkt
401 !fire`
402
403 | 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` |
413
414 If you don't prefer fuzzy matching and do not wish to "quote" every word,
415 start fzf with `-e` or `--exact` option. Note that when `--exact` is set,
416 `'`-prefix "unquotes" the term.
417
418 A single bar character term acts as an OR operator. For example, the following
419 query matches entries that start with `core` and end with either `go`, `rb`,
420 or `py`.
421
422 ```
423 ^core go$ | rb$ | py$
424 ```
425
426 ### Environment variables
427
428 - `FZF_DEFAULT_COMMAND`
429 - Default command to use when input is tty
430 - e.g. `export FZF_DEFAULT_COMMAND='fd --type f'`
431 - `FZF_DEFAULT_OPTS`
432 - Default options
433 - 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 to
436 point to the location of the file
437 - e.g. `export FZF_DEFAULT_OPTS_FILE=~/.fzfrc`
438
439 > [!WARNING]
440 > `FZF_DEFAULT_COMMAND` is not used by shell integration due to the
441 > slight difference in requirements.
442 >
443 > * `CTRL-T` runs `$FZF_CTRL_T_COMMAND` to get a list of files and directories
444 > * `ALT-C` runs `$FZF_ALT_C_COMMAND` to get a list of directories
445 > * `vim ~/**<tab>` runs `fzf_compgen_path()` with the prefix (`~/`) as the first argument
446 > * `cd foo**<tab>` runs `fzf_compgen_dir()` with the prefix (`foo`) as the first argument
447 >
448 > The available options are described later in this document.
449
450 ### Customizing the look
451
452 The user interface of fzf is fully customizable with a large number of
453 configuration options. For a quick setup, you can start with one of the style
454 presets -- `default`, `full`, or `minimal` -- using the `--style` option.
455
456 ```sh
457 fzf --style full \
458 --preview 'fzf-preview.sh {}' --bind 'focus:transform-header:file --brief {}'
459 ```
460
461 | 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"/> |
466
467 Here's an example based on the `full` preset:
468
469 <img src="https://raw.githubusercontent.com/junegunn/i/master/fzf-4-borders.png"/>
470
471 <details>
472
473 ```sh
474 git 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 ]]; then
480 echo " $FZF_MATCH_COUNT items "
481 else
482 echo " $FZF_MATCH_COUNT matches for [$FZF_QUERY] "
483 fi
484 ' \
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 ```
494
495 </details>
496
497 ### Options
498
499 See the man page (`fzf --man` or `man fzf`) for the full list of options.
500
501 ### Demo
502 If you learn by watching videos, check out this screencast by [@samoshkin](https://github.com/samoshkin) to explore `fzf` features.
503
504 <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>
507
508 Examples
509 --------
510
511 * [Wiki page of examples](https://github.com/junegunn/fzf/wiki/examples)
512 * *Disclaimer: The examples on this page are maintained by the community
513 and are not thoroughly tested*
514 * [Advanced fzf examples](https://github.com/junegunn/fzf/blob/master/ADVANCED.md)
515
516 Key bindings for command-line
517 -----------------------------
518
519 By [setting up shell integration](#setting-up-shell-integration), you can use
520 the following key bindings in bash, zsh, fish, and Nushell.
521
522 - `CTRL-T` - Paste the selected files and directories onto the command-line
523 - The list is generated using `--walker file,dir,follow,hidden` option
524 - You can override the behavior by setting `FZF_CTRL_T_COMMAND` to a custom command that generates the desired list
525 - Or you can set `--walker*` options in `FZF_CTRL_T_OPTS`
526 - Set `FZF_CTRL_T_OPTS` to pass additional options to fzf
527 ```sh
528 # Preview file content using bat (https://github.com/sharkdp/bat)
529 export FZF_CTRL_T_OPTS="
530 --walker-skip .git,node_modules,target
531 --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 when
535 sourcing the script
536 - `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 relevance
540 - Press `ALT-R` to toggle "raw" mode where you can see the surrounding items
541 of a match. In this mode, you can press `CTRL-N` and `CTRL-P` to move
542 between the matching items only.
543 - Press `CTRL-/` or `ALT-/` to toggle line wrapping
544 - 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 commands
547 - Press `ALT-T` to cycle through command prefix (timestamp, date/time, none)
548 - Set `FZF_CTRL_R_OPTS` to pass additional options to fzf
549 ```sh
550 # CTRL-Y to copy the command into clipboard using pbcopy
551 export FZF_CTRL_R_OPTS="
552 --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'
553 --color header:italic
554 --header 'Press CTRL-Y to copy command into clipboard'"
555 ```
556 ```fish
557 # Fish shell: Set date/time as default prefix
558 set -gx FZF_CTRL_R_OPTS "--with-nth 1,3.. --bind 'alt-t:change-with-nth(2..|3..|1,3..)'"
559
560 # Or display no prefix by default
561 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 when
564 sourcing the script
565 - Custom override via a non-empty `FZF_CTRL_R_COMMAND` is not yet supported and will emit a warning
566 - `ALT-C` - cd into the selected directory
567 - The list is generated using `--walker dir,follow,hidden` option
568 - Set `FZF_ALT_C_COMMAND` to override the default command
569 - Or you can set `--walker-*` options in `FZF_ALT_C_OPTS`
570 - Set `FZF_ALT_C_OPTS` to pass additional options to fzf
571 ```sh
572 # Print tree structure in the preview window
573 export FZF_ALT_C_OPTS="
574 --walker-skip .git,node_modules,target
575 --preview 'tree -C {}'"
576 ```
577 - Can be disabled by setting `FZF_ALT_C_COMMAND` to an empty string when
578 sourcing the script
579
580 Display modes for these bindings can be separately configured via
581 `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'`)
583
584 More tips can be found on [the wiki page](https://github.com/junegunn/fzf/wiki/Configuring-shell-key-bindings).
585
586 Fuzzy completion
587 ----------------
588
589 Shell integration also provides fuzzy completion for bash, zsh, fish, and Nushell.
590
591 ### Files and directories
592
593 Fuzzy completion for files and directories can be triggered if the word before
594 the cursor ends with the trigger sequence, which is by default `**`.
595
596 - `COMMAND [DIRECTORY/][FUZZY_PATTERN]**<TAB>`
597
598 ```sh
599 # Files under the current directory
600 # - You can select multiple items with TAB key
601 vim **<TAB>
602
603 # Files under parent directory
604 vim ../**<TAB>
605
606 # Files under parent directory that match `fzf`
607 vim ../fzf**<TAB>
608
609 # Files under your home directory
610 vim ~/**<TAB>
611
612
613 # Directories under current directory (single-selection)
614 cd **<TAB>
615
616 # Directories under ~/github that match `fzf`
617 cd ~/github/fzf**<TAB>
618 ```
619
620 ### Process IDs
621
622 Fuzzy completion for PIDs is provided for kill command.
623
624 ```sh
625 # Can select multiple processes with <TAB> or <Shift-TAB> keys
626 kill -9 **<TAB>
627 ```
628
629 ### Host names
630
631 For ssh command, fuzzy completion for hostnames is provided. The names are
632 extracted from /etc/hosts and ~/.ssh/config.
633
634 ```sh
635 ssh **<TAB>
636 ```
637
638 ### Environment variables / Aliases
639
640 ```sh
641 # bash and zsh
642 unset **<TAB>
643 export **<TAB>
644 unalias **<TAB>
645
646 # fish
647 set <SHIFT-TAB>
648 ```
649
650 ### Customizing fuzzy completion for bash and zsh
651
652 #### Customizing fzf options for completion
653
654 ```sh
655 # Use ~~ as the trigger sequence instead of the default **
656 export FZF_COMPLETION_TRIGGER='~~'
657
658 # Options to fzf command
659 export FZF_COMPLETION_OPTS='--border --info=inline'
660
661 # Options for path completion (e.g. vim **<TAB>)
662 export FZF_COMPLETION_PATH_OPTS='--walker file,dir,follow,hidden'
663
664 # Options for directory completion (e.g. cd **<TAB>)
665 export FZF_COMPLETION_DIR_OPTS='--walker dir,follow'
666
667 # Advanced customization of fzf options via _fzf_comprun function
668 # - 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=$1
672 shift
673
674 case "$command" in
675 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 esac
680 }
681 ```
682
683 #### Customizing completion source for paths and directories
684
685 ```sh
686 # 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 traversal
688 # - See the source code (completion.{bash,zsh}) for the details.
689 _fzf_compgen_path() {
690 fd --hidden --follow --exclude ".git" . "$1"
691 }
692
693 # Use fd to generate the list for directory completion
694 _fzf_compgen_dir() {
695 fd --type d --hidden --follow --exclude ".git" . "$1"
696 }
697 ```
698
699 #### Supported commands (bash)
700
701 On bash, fuzzy completion is enabled only for a predefined set of commands
702 (`complete | grep _fzf` to see the list). But you can enable it for other
703 commands as well by using `_fzf_setup_completion` helper function.
704
705 ```sh
706 # usage: _fzf_setup_completion path|dir|var|alias|host COMMANDS...
707 _fzf_setup_completion path ag git kubectl
708 _fzf_setup_completion dir tree
709 ```
710
711 #### Custom fuzzy completion
712
713 _**(Custom completion API is experimental and subject to change)**_
714
715 For a command named _"COMMAND"_, define `_fzf_complete_COMMAND` function using
716 `_fzf_complete` helper.
717
718 ```sh
719 # Custom fuzzy completion for "doge" command
720 # e.g. doge **<TAB>
721 _fzf_complete_doge() {
722 _fzf_complete --multi --reverse --prompt="doge> " -- "$@" < <(
723 echo very
724 echo wow
725 echo such
726 echo doge
727 )
728 }
729 ```
730
731 - 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 and
734 feed its output to the function using process substitution (`< <(...)`).
735
736 zsh will automatically pick up the function using the naming convention but in
737 bash you have to manually associate the function with the command using the
738 `complete` command.
739
740 ```sh
741 [ -n "$BASH" ] && complete -F _fzf_complete_doge -o default -o bashdefault doge
742 ```
743
744 If you need to post-process the output from fzf, define
745 `_fzf_complete_COMMAND_post` as follows.
746
747 ```sh
748 _fzf_complete_foo() {
749 _fzf_complete --multi --reverse --header-lines=3 -- "$@" < <(
750 ls -al
751 )
752 }
753
754 _fzf_complete_foo_post() {
755 awk '{print $NF}'
756 }
757
758 [ -n "$BASH" ] && complete -F _fzf_complete_foo -o default -o bashdefault foo
759 ```
760
761 ### Fuzzy completion for fish
762
763 Fuzzy completion for fish differs from bash and zsh in that:
764
765 - It doesn't require a trigger sequence like `**`. Instead, if activates
766 on `Shift-TAB` (replacing the native pager search mode), while `TAB` preserves
767 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 recursive
770 searching, use the `CTRL-T` binding instead.
771 - If the current command line token is a wildcard pattern, it performs search on
772 the wildcard expansion path list (instead of the native behavior of inserting
773 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` and
776 `FZF_EXPANSION_OPS`.
777 - The function that is used by custom completion functions is named
778 `fzf_complete`, which only accepts fzf options as arguments, and can be also
779 called without any redirected input, to just modify fzf options while
780 presenting the native completion results. For compatibility with other shells,
781 a function named `_fzf_complete` is provided, that can accept ` -- $argv` in
782 its command line arguments, after fzf options.
783
784 For commands that are not covered by fish completions, it is better to create
785 regular fish completion functions (which will work for both `TAB` and
786 `Shift-TAB`), and create fzf completion functions only when needing to modify
787 fzf options for a specific command or want different results for `Shift-TAB`:
788
789 ```fish
790 # Customize git completion
791 function _fzf_complete_git
792 # Show header text with active branch for all git completions
793 set -lx -- FZF_COMPLETION_OPTS --header="'"(git branch --show-current 2>/dev/null)"'"
794
795 # No other changes when less than 3 arguments, or when completing options
796 if not set -q argv[3]; or string match -q -- '-*' $argv[-1]
797 fzf_complete
798 return
799 end
800
801 # Check subcommand
802 switch $argv[2]
803 case checkout diff log show
804 # Set preview and display all branches and commits for subcommands: checkout, diff, log, show
805 begin
806 git branch --all --format='%(refname:short)'
807 git log --all --oneline --color=always
808 end | fzf_complete --no-multi --ansi --accept-nth=1 --query=$argv[-1] --preview='git show --color=always {1}'
809
810 case add rm mv
811 # Only set preview for subcommands: add, rm, mv
812 # Special characters in fish completion lists are escaped, so the r flag must be used.
813 fzf_complete --preview="git diff --color=always {r1}"
814
815 case '*'
816 # No changes for other subcommands
817 fzf_complete
818 end
819 end
820 ```
821
822 Similar to bash and zsh, the output of fzf can be processed before inserted in
823 command line, by defining a function named `_fzf_complete_COMMAND_post` or
824 `_fzf_post_complete_COMMAND`:
825
826 ```fish
827 function _fzf_complete_foo
828 ls -sh --zero --color=always | fzf_complete --read0 --print0 --ansi --no-multi-line --header-lines=1
829 end
830
831 function _fzf_post_complete_foo
832 while read -lz result
833 string escape -n -- $result | string trim -l -c '\ ' | string split -m 1 -f 2 ' '
834 end
835 end
836 ```
837
838 ### Fuzzy completion for Nushell
839
840 Fuzzy completion in Nushell works via the
841 [external completer](https://www.nushell.sh/cookbook/external_completers.html)
842 mechanism. There are some differences compared to bash and zsh:
843
844 - On Nushell >= 0.103.0, the external completer is no longer called for
845 built-in commands (e.g. `cd`, `ls`). Fuzzy completion with `**<TAB>` only
846 works for external commands.
847 - Custom completers can be defined via the `$env.FZF_COMPLETERS` record in
848 your `config.nu`. Each entry is a closure that receives the prefix and the
849 command spans, and returns either a list of candidate strings or a record
850 `{ candidates: [...], opts: [...] }` for custom fzf options:
851 ```nu
852 $env.FZF_COMPLETERS = {
853 pacman: {|prefix, spans|
854 let sub = $spans | skip 1 | first
855 let candidates = (if ($sub =~ "-[SF]") { ^pacman -Slq | lines
856 } else if ($sub =~ "-[QR]") { ^pacman -Qq | lines
857 } else { [] })
858 { candidates: $candidates, opts: ["--preview", "pacman -Si {}"] }
859 }
860 }
861 ```
862 See [shell/completion-examples.nu](shell/completion-examples.nu) for more
863 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`.
868
869 Vim plugin
870 ----------
871
872 See [README-VIM.md](README-VIM.md).
873
874 Advanced topics
875 ---------------
876
877 ### Customizing for different types of input
878
879 Since fzf is a general-purpose text filter, its algorithm was designed to
880 "generally" work well with any kind of input. However, admittedly, there is no
881 true one-size-fits-all solution, and you may want to tweak the algorithm and
882 some of the settings depending on the type of the input. To make this process
883 easier, fzf provides a set of "scheme"s for some common input types.
884
885 | 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 |
890
891 (See `fzf --man` for the details)
892
893 ### Performance
894
895 fzf is fast. Performance should not be a problem in most use cases. However,
896 you might want to be aware of the options that can affect performance.
897
898 - `--ansi` tells fzf to extract and parse ANSI color codes in the input, and it
899 makes the initial scanning slower. So it's not recommended that you add it
900 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 expression
903 delimiter.
904 - `--with-nth` makes fzf slower as fzf has to tokenize and reassemble each
905 line.
906
907 ### Executing external programs
908
909 You can set up key bindings for starting external processes without leaving
910 fzf (`execute`, `execute-silent`).
911
912 ```bash
913 # Press F1 to open the file with less without leaving fzf
914 # Press CTRL-Y to copy the line to clipboard and aborts fzf (requires pbcopy)
915 fzf --bind 'f1:execute(less -f {}),ctrl-y:execute-silent(echo {} | pbcopy)+abort'
916 ```
917
918 See *KEY/EVENT BINDINGS* section of the man page for details.
919
920 ### Turning into a different process
921
922 `become(...)` is similar to `execute(...)`/`execute-silent(...)` described
923 above, but instead of executing the command and coming back to fzf on
924 complete, it turns fzf into a new process for the command.
925
926 ```sh
927 fzf --bind 'enter:become(vim {})'
928 ```
929
930 Compared to the seemingly equivalent command substitution `vim "$(fzf)"`, this
931 approach has several advantages:
932
933 * Vim will not open an empty file when you terminate fzf with
934 <kbd>CTRL-C</kbd>
935 * Vim will not open an empty file when you press <kbd>ENTER</kbd> on an empty
936 result
937 * Can handle multiple selections even when they have whitespaces
938 ```sh
939 fzf --multi --bind 'enter:become(vim {+})'
940 ```
941
942 To be fair, running `fzf --print0 | xargs -0 -o vim` instead of `vim "$(fzf)"`
943 resolves all of the issues mentioned. Nonetheless, `become(...)` still offers
944 additional benefits in different scenarios.
945
946 * You can set up multiple bindings to handle the result in different ways
947 without any wrapping script
948 ```sh
949 fzf --bind 'enter:become(vim {}),ctrl-e:become(emacs {})'
950 ```
951 * Previously, you would have to use `--expect=ctrl-e` and check the first
952 line of the output of fzf
953 * You can easily build the subsequent command using the field index
954 expressions of fzf
955 ```sh
956 # Open the file in Vim and go to the line
957 git grep --line-number . |
958 fzf --delimiter : --nth 3.. --bind 'enter:become(vim {1} +{2})'
959 ```
960
961 ### Reloading the candidate list
962
963 By binding `reload` action to a key or an event, you can make fzf dynamically
964 reload the candidate list. See https://github.com/junegunn/fzf/issues/1750 for
965 more details.
966
967 #### 1. Update the list of processes by pressing CTRL-R
968
969 ```sh
970 ps -ef |
971 fzf --bind 'ctrl-r:reload(ps -ef)' \
972 --header 'Press CTRL-R to reload' --header-lines=1 \
973 --height=50% --layout=reverse
974 ```
975
976 #### 2. Switch between sources by pressing CTRL-D or CTRL-F
977
978 ```sh
979 FZF_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=reverse
982 ```
983
984 #### 3. Interactive ripgrep integration
985
986 The following example uses fzf as the selector interface for ripgrep. We bound
987 `reload` action to `change` event, so every time you type on fzf, the ripgrep
988 process will restart with the updated query string denoted by the placeholder
989 expression `{q}`. Also, note that we used `--disabled` option so that fzf
990 doesn't perform any secondary filtering.
991
992 ```sh
993 : | 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=reverse
999 ```
1000
1001 If ripgrep doesn't find any matches, it will exit with a non-zero exit status,
1002 and fzf will warn you about it. To suppress the warning message, we added
1003 `|| true` to the command, so that it always exits with 0.
1004
1005 See ["Using fzf as interactive Ripgrep launcher"](https://github.com/junegunn/fzf/blob/master/ADVANCED.md#using-fzf-as-interactive-ripgrep-launcher)
1006 for more sophisticated examples.
1007
1008 ### Preview window
1009
1010 When the `--preview` option is set, fzf automatically starts an external process
1011 with the current line as the argument and shows the result in the split window.
1012 Your `$SHELL` is used to execute the command with `$SHELL -c COMMAND`.
1013 The window can be scrolled using the mouse or custom key bindings.
1014
1015 ```bash
1016 # {} is replaced with the single-quoted string of the focused line
1017 fzf --preview 'cat {}'
1018 ```
1019
1020 Preview window supports ANSI colors, so you can use any program that
1021 syntax-highlights the content of a file, such as
1022 [Bat](https://github.com/sharkdp/bat) or
1023 [Highlight](https://gitlab.com/saalen/highlight):
1024
1025 ```bash
1026 fzf --preview 'bat --color=always {}' --preview-window '~3'
1027 ```
1028
1029 You can customize the size, position, and border of the preview window using
1030 `--preview-window` option, and the foreground and background color of it with
1031 `--color` option. For example,
1032
1033 ```bash
1034 fzf --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 ```
1039
1040 See the man page (`man fzf`) for the full list of options.
1041
1042 More advanced examples can be found [here](https://github.com/junegunn/fzf/blob/master/ADVANCED.md).
1043
1044 > [!WARNING]
1045 > Since fzf is a general-purpose text filter rather than a file finder, **it is
1046 > not a good idea to add `--preview` option to your `$FZF_DEFAULT_OPTS`**.
1047 >
1048 > ```sh
1049 > # *********************
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 files
1055 > ps -ef | fzf
1056 > seq 100 | fzf
1057 > history | fzf
1058 > ```
1059
1060 ### Previewing an image
1061
1062 fzf can display images in the preview window using one of the following protocols:
1063
1064 * [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)
1067
1068 See [bin/fzf-preview.sh](bin/fzf-preview.sh) script for more information.
1069
1070 ```sh
1071 fzf --preview 'fzf-preview.sh {}'
1072 ```
1073
1074 Tips
1075 ----
1076
1077 ### Respecting `.gitignore`
1078
1079 You can use [fd](https://github.com/sharkdp/fd),
1080 [ripgrep](https://github.com/BurntSushi/ripgrep), or [the silver
1081 searcher](https://github.com/ggreer/the_silver_searcher) to traverse the file
1082 system while respecting `.gitignore`.
1083
1084 ```sh
1085 # Feed the output of fd into fzf
1086 fd --type f --strip-cwd-prefix | fzf
1087
1088 # Setting fd as the default source for fzf
1089 export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix'
1090
1091 # Now fzf (w/o pipe) will use the fd command to generate the list
1092 fzf
1093
1094 # To apply the command to CTRL-T as well
1095 export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
1096 ```
1097
1098 If you want the command to follow symbolic links and don't want it to exclude
1099 hidden files, use the following command:
1100
1101 ```sh
1102 export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix --hidden --follow --exclude .git'
1103 ```
1104
1105 ### Fish shell
1106
1107 `CTRL-T` key binding of fish, unlike those of bash and zsh, will use the last
1108 token on the command-line as the root directory for the recursive search. For
1109 instance, hitting `CTRL-T` at the end of the following command-line
1110
1111 ```sh
1112 ls /var/
1113 ```
1114
1115 will list all files and directories under `/var/`.
1116
1117 When using a custom `FZF_CTRL_T_COMMAND`, use the unexpanded `$dir` variable to
1118 make use of this feature. `$dir` defaults to `.` when the last token is not a
1119 valid directory. Example:
1120
1121 ```sh
1122 set -g FZF_CTRL_T_COMMAND "command find -L \$dir -type f 2> /dev/null | sed '1d; s#^\./##'"
1123 ```
1124
1125 ### fzf Theme Playground
1126
1127 [fzf Theme Playground](https://vitormv.github.io/fzf-themes/) created by
1128 [Vitor Mello](https://github.com/vitormv) is a webpage where you can
1129 interactively create fzf themes.
1130
1131 Related projects
1132 ----------------
1133
1134 https://github.com/junegunn/fzf/wiki/Related-projects
1135
1136 [License](LICENSE)
1137 ------------------
1138
1139 The MIT License (MIT)
1140
1141 Copyright (c) 2013-2026 Junegunn Choi
1142
1143 Goods
1144 -----
1145
1146 Grab fzf T-shirts, mugs, and stickers here: https://commitgoods.com/collections/fzf
1147
1148 Sponsors :heart:
1149 ----------------
1150
1151 I would like to thank all the sponsors of this project who make it possible for me to continue to improve fzf.
1152
1153 If you'd like to sponsor this project, please visit https://github.com/sponsors/junegunn.