Skip to content
Myr

Show how to use reload action

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 9dfca77 · Browse files · 1 file+88 added−36 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+88 added−36 removed

  • other:+88 added−36 removed

1 file+88 added−36 removed

modified:README.md+88 added-36 removed
20 unmodified lines
2122Table of Contents23-----------------2425 * [Installation](#installation)26 * [Using Homebrew or Linuxbrew](#using-homebrew-or-linuxbrew)27 * [Using git](#using-git)28 * [Using Linux package managers](#using-linux-package-managers)29 * [Windows](#windows)30 * [As Vim plugin](#as-vim-plugin)31 * [Upgrading fzf](#upgrading-fzf)32 * [Building fzf](#building-fzf)33 * [Usage](#usage)34 * [Using the finder](#using-the-finder)35 * [Layout](#layout)36 * [Search syntax](#search-syntax)37 * [Environment variables](#environment-variables)38 * [Options](#options)39 * [Demo](#demo)40 * [Examples](#examples)41 * [fzf-tmux script](#fzf-tmux-script)42 * [Key bindings for command line](#key-bindings-for-command-line)43 * [Fuzzy completion for bash and zsh](#fuzzy-completion-for-bash-and-zsh)44 * [Files and directories](#files-and-directories)45 * [Process IDs](#process-ids)46 * [Host names](#host-names)47 * [Environment variables / Aliases](#environment-variables--aliases)48 * [Settings](#settings)49 * [Supported commands](#supported-commands)50 * [Custom fuzzy completion](#custom-fuzzy-completion)51 * [Vim plugin](#vim-plugin)52 * [Advanced topics](#advanced-topics)53 * [Performance](#performance)54 * [Executing external programs](#executing-external-programs)55 * [Preview window](#preview-window)56 * [Tips](#tips)57 * [Respecting .gitignore](#respecting-gitignore)58 * [Fish shell](#fish-shell)59 * [Related projects](#related-projects)60 * [<a href="LICENSE">License</a>](#license)25<!-- vim-markdown-toc GFM -->2627* [Installation](#installation)28 * [Using Homebrew or Linuxbrew](#using-homebrew-or-linuxbrew)29 * [Using git](#using-git)30 * [Using Linux package managers](#using-linux-package-managers)31 * [Windows](#windows)32 * [As Vim plugin](#as-vim-plugin)33* [Upgrading fzf](#upgrading-fzf)34* [Building fzf](#building-fzf)35* [Usage](#usage)36 * [Using the finder](#using-the-finder)37 * [Layout](#layout)38 * [Search syntax](#search-syntax)39 * [Environment variables](#environment-variables)40 * [Options](#options)41 * [Demo](#demo)42* [Examples](#examples)43* [`fzf-tmux` script](#fzf-tmux-script)44* [Key bindings for command-line](#key-bindings-for-command-line)45* [Fuzzy completion for bash and zsh](#fuzzy-completion-for-bash-and-zsh)46 * [Files and directories](#files-and-directories)47 * [Process IDs](#process-ids)48 * [Host names](#host-names)49 * [Environment variables / Aliases](#environment-variables--aliases)50 * [Settings](#settings)51 * [Supported commands](#supported-commands)52 * [Custom fuzzy completion](#custom-fuzzy-completion)53* [Vim plugin](#vim-plugin)54* [Advanced topics](#advanced-topics)55 * [Performance](#performance)56 * [Executing external programs](#executing-external-programs)57 * [Reloading the candidate list](#reloading-the-candidate-list)58 * [1. Update the list of processes by pressing CTRL-R](#1-update-the-list-of-processes-by-pressing-ctrl-r)59 * [2. Switch between sources by pressing CTRL-D or CTRL-F](#2-switch-between-sources-by-pressing-ctrl-d-or-ctrl-f)60 * [3. Interactive ripgrep integration](#3-interactive-ripgrep-integration)61 * [Preview window](#preview-window)62* [Tips](#tips)63 * [Respecting `.gitignore`](#respecting-gitignore)64 * [Fish shell](#fish-shell)65* [Related projects](#related-projects)66* [License](#license)6768<!-- vim-markdown-toc -->6970Installation71------------7273fzf project consists of the following components:
461 unmodified lines
535```536537See *KEY BINDINGS* section of the man page for details.538539### Reloading the candidate list540541By binding `reload` action to a key or an event, you can make fzf dynamically542reload the candidate list. See https://github.com/junegunn/fzf/issues/1750 for543more details.544545#### 1. Update the list of processes by pressing CTRL-R546547```sh548FZF_DEFAULT_COMMAND='ps -ef' \549 fzf --bind 'ctrl-r:reload($FZF_DEFAULT_COMMAND)' \550 --header 'Press CTRL-R to reload' --header-lines=1 \551 --height=50% --layout=reverse552```553554#### 2. Switch between sources by pressing CTRL-D or CTRL-F555556```sh557FZF_DEFAULT_COMMAND='find . -type f' \558 fzf --bind 'ctrl-d:reload(find . -type d),ctrl-f:reload($FZF_DEFAULT_COMMAND)' \559 --height=50% --layout=reverse560```561562#### 3. Interactive ripgrep integration563564The following example uses fzf as the selector interface for ripgrep. We bound565`reload` action to `change` event, so every time you type on fzf, ripgrep566process will restart with the updated query string denoted by the placeholder567expression `{q}`. Also, note that we used `--phony` option so that fzf doesn't568perform any secondary filtering.569570```sh571INITIAL_QUERY=""572RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "573FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \574 fzf --bind "change:reload:$RG_PREFIX {q} || true" \575 --ansi --phony --query "$INITIAL_QUERY" \576 --height=50% --layout=reverse577```578579If ripgrep doesn't find any matches, it will exit with a non-zero exit status,580and fzf will warn you about it. To suppress the warning message, we added581`|| true` to the command, so that it always exits with 0.582583### Preview window584585When the `--preview` option is set, fzf automatically starts an external process 586with the current line as the argument and shows the result in the split window.
122 unmodified lines