From 23f898eff8a4d988c7f79694e827a6df5322262d Mon Sep 17 00:00:00 2001 From: wehub-resource-sync Date: Mon, 13 Jul 2026 09:50:27 +0000 Subject: [PATCH] docs: make Chinese README the default --- README.md | 900 +++++++++++++++++++++++++----------------------------- 1 file changed, 412 insertions(+), 488 deletions(-) diff --git a/README.md b/README.md index d4d1838..5435b78 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,27 @@ + +> [!NOTE] +> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。 +> [English](./README.en.md) · [原始项目](https://github.com/junegunn/fzf) · [上游 README](https://github.com/junegunn/fzf/blob/HEAD/README.md) +> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。 +
- fzf - a command-line fuzzy finder - Build Status - Version - License - Contributors - Sponsors - Stars + fzf - 命令行模糊查找器 + 构建状态 + 版本 + 许可证 + 贡献者 + 赞助者 + 星标
---
- fzf merch + fzf 周边

- Show your love for fzf -- T-shirts, mugs, and stickers now available! + 表达对 fzf 的喜爱——T 恤、马克杯和贴纸现已上架!

commitgoods.com/collections/fzf @@ -25,116 +31,116 @@ --- -fzf is a general-purpose command-line fuzzy finder and an interactive terminal toolkit. +fzf 是一款通用命令行模糊查找器(fuzzy finder)和交互式终端工具包。 -Whether you're selecting files, browsing command history, previewing data, -navigating complex datasets with fuzzy matching, or creating custom menus and -workflows, fzf provides the building blocks to turn shell scripts into rich -terminal applications. +无论你是选择文件、浏览命令历史、预览数据、 +通过模糊匹配浏览复杂数据集,还是创建自定义菜单和 +工作流,fzf 都提供了将 shell 脚本转变为丰富 +终端应用所需的构建模块。 -Highlights +亮点 ---------- -- **Portable** // Distributed as a single binary for easy installation -- **Fast** // Optimized to process millions of items in milliseconds -- **Programmable** // Event-driven architecture for building custom terminal interfaces and workflows -- **Batteries-included** // Comes with integrations for Bash, Zsh, Fish, Nushell, Vim, and Neovim +- **便携** // 以单一二进制文件分发,便于安装 +- **快速** // 经过优化,可在毫秒内处理数百万条目 +- **可编程** // 事件驱动架构,用于构建自定义终端界面和工作流 +- **开箱即用** // 内置与 Bash、Zsh、Fish、Nushell、Vim 和 Neovim 的集成 -Table of Contents +目录 ----------------- -* [Installation](#installation) - * [Using Homebrew](#using-homebrew) - * [Using Mise](#using-mise) - * [Linux packages](#linux-packages) - * [Windows packages](#windows-packages) - * [Using git](#using-git) - * [Binary releases](#binary-releases) - * [Setting up shell integration](#setting-up-shell-integration) - * [Vim/Neovim plugin](#vimneovim-plugin) -* [Upgrading fzf](#upgrading-fzf) -* [Building fzf](#building-fzf) -* [Usage](#usage) - * [Using the finder](#using-the-finder) - * [Display modes](#display-modes) - * [`--height` mode](#--height-mode) - * [`--popup` mode](#--popup-mode) - * [Search syntax](#search-syntax) - * [Environment variables](#environment-variables) - * [Customizing the look](#customizing-the-look) - * [Options](#options) - * [Demo](#demo) -* [Examples](#examples) -* [Key bindings for command-line](#key-bindings-for-command-line) -* [Fuzzy completion](#fuzzy-completion) - * [Files and directories](#files-and-directories) - * [Process IDs](#process-ids) - * [Host names](#host-names) - * [Environment variables / Aliases](#environment-variables--aliases) - * [Customizing fuzzy completion for bash and zsh](#customizing-fuzzy-completion-for-bash-and-zsh) - * [Customizing fzf options for completion](#customizing-fzf-options-for-completion) - * [Customizing completion source for paths and directories](#customizing-completion-source-for-paths-and-directories) - * [Supported commands (bash)](#supported-commands-bash) - * [Custom fuzzy completion](#custom-fuzzy-completion) - * [Fuzzy completion for fish](#fuzzy-completion-for-fish) - * [Fuzzy completion for Nushell](#fuzzy-completion-for-nushell) -* [Vim plugin](#vim-plugin) -* [Advanced topics](#advanced-topics) - * [Customizing for different types of input](#customizing-for-different-types-of-input) - * [Performance](#performance) - * [Executing external programs](#executing-external-programs) - * [Turning into a different process](#turning-into-a-different-process) - * [Reloading the candidate list](#reloading-the-candidate-list) - * [1. Update the list of processes by pressing CTRL-R](#1-update-the-list-of-processes-by-pressing-ctrl-r) - * [2. Switch between sources by pressing CTRL-D or CTRL-F](#2-switch-between-sources-by-pressing-ctrl-d-or-ctrl-f) - * [3. Interactive ripgrep integration](#3-interactive-ripgrep-integration) - * [Preview window](#preview-window) - * [Previewing an image](#previewing-an-image) -* [Tips](#tips) - * [Respecting `.gitignore`](#respecting-gitignore) +* [安装](#installation) + * [使用 Homebrew](#using-homebrew) + * [使用 Mise](#using-mise) + * [Linux 软件包](#linux-packages) + * [Windows 软件包](#windows-packages) + * [使用 git](#using-git) + * [二进制发行版](#binary-releases) + * [配置 shell 集成](#setting-up-shell-integration) + * [Vim/Neovim 插件](#vimneovim-plugin) +* [升级 fzf](#upgrading-fzf) +* [构建 fzf](#building-fzf) +* [用法](#usage) + * [使用查找器](#using-the-finder) + * [显示模式](#display-modes) + * [`--height` 模式](#--height-mode) + * [`--popup` 模式](#--popup-mode) + * [搜索语法](#search-syntax) + * [环境变量](#environment-variables) + * [自定义外观](#customizing-the-look) + * [选项](#options) + * [演示](#demo) +* [示例](#examples) +* [命令行快捷键](#key-bindings-for-command-line) +* [模糊补全](#fuzzy-completion) + * [文件和目录](#files-and-directories) + * [进程 ID](#process-ids) + * [主机名](#host-names) + * [环境变量 / 别名](#environment-variables--aliases) + * [为 bash 和 zsh 自定义模糊补全](#customizing-fuzzy-completion-for-bash-and-zsh) + * [自定义 fzf 补全选项](#customizing-fzf-options-for-completion) + * [自定义路径和目录的补全来源](#customizing-completion-source-for-paths-and-directories) + * [支持的命令(bash)](#supported-commands-bash) + * [自定义模糊补全](#custom-fuzzy-completion) + * [Fish 的模糊补全](#fuzzy-completion-for-fish) + * [Nushell 的模糊补全](#fuzzy-completion-for-nushell) +* [Vim 插件](#vim-plugin) +* [高级主题](#advanced-topics) + * [针对不同输入类型的自定义](#customizing-for-different-types-of-input) + * [性能](#performance) + * [执行外部程序](#executing-external-programs) + * [切换为不同进程](#turning-into-a-different-process) + * [重新加载候选列表](#reloading-the-candidate-list) + * [1. 按 CTRL-R 更新进程列表](#1-update-the-list-of-processes-by-pressing-ctrl-r) + * [2. 按 CTRL-D 或 CTRL-F 在来源之间切换](#2-switch-between-sources-by-pressing-ctrl-d-or-ctrl-f) + * [3. 交互式 ripgrep 集成](#3-interactive-ripgrep-integration) + * [预览窗口](#preview-window) + * [预览图片](#previewing-an-image) +* [技巧](#tips) + * [遵循 `.gitignore`](#respecting-gitignore) * [Fish shell](#fish-shell) - * [fzf Theme Playground](#fzf-theme-playground) -* [Related projects](#related-projects) -* [License](#license) -* [Goods](#goods) -* [Sponsors :heart:](#sponsors-heart) + * [fzf 主题游乐场](#fzf-theme-playground) +* [相关项目](#related-projects) +* [许可证](#license) +* [周边商品](#goods) +* [赞助者 :heart:](#sponsors-heart) -Installation +安装 ------------ -### Using Homebrew +### 使用 Homebrew -You can use [Homebrew](https://brew.sh/) (on macOS or Linux) to install fzf. +你可以使用 [Homebrew](https://brew.sh/)(在 macOS 或 Linux 上)安装 fzf。 ```sh brew install fzf ``` > [!IMPORTANT] -> To set up shell integration (key bindings and fuzzy completion), -> see [the instructions below](#setting-up-shell-integration). +> 要配置 shell 集成(快捷键和模糊补全), +> 请参阅[下方说明](#setting-up-shell-integration)。 -fzf is also available [via MacPorts][portfile]: `sudo port install fzf` +fzf 也可通过 [MacPorts][portfile] 获取:`sudo port install fzf` [portfile]: https://github.com/macports/macports-ports/blob/master/sysutils/fzf/Portfile -### Using Mise +### 使用 Mise -You can use [mise](https://github.com/jdx/mise) to install fzf. +你可以使用 [mise](https://github.com/jdx/mise) 安装 fzf。 ```sh mise use -g fzf@latest ``` -### Linux packages +### Linux 软件包 -| Package Manager | Linux Distribution | Command | +| 软件包管理器 | Linux 发行版 | 命令 | | --------------- | ----------------------- | ---------------------------------- | | APK | Alpine Linux | `sudo apk add fzf` | | APT | Debian 9+/Ubuntu 19.10+ | `sudo apt install fzf` | @@ -151,17 +157,17 @@ mise use -g fzf@latest | Zypper | openSUSE | `sudo zypper install fzf` | > [!IMPORTANT] -> To set up shell integration (key bindings and fuzzy completion), -> see [the instructions below](#setting-up-shell-integration). +> 要配置 shell 集成(快捷键和模糊补全), +> 请参阅[下方说明](#setting-up-shell-integration)。 [![Packaging status](https://repology.org/badge/vertical-allrepos/fzf.svg?columns=3)](https://repology.org/project/fzf/versions) -### Windows packages +### Windows 软件包 -On Windows, fzf is available via [Chocolatey][choco], [Scoop][scoop], -[Winget][winget], and [MSYS2][msys2]: +在 Windows 上,可通过 [Chocolatey][choco]、[Scoop][scoop]、 +[Winget][winget] 和 [MSYS2][msys2] 安装 fzf: -| Package manager | Command | +| 软件包管理器 | 命令 | | --------------- | ------------------------------------- | | Chocolatey | `choco install fzf` | | Scoop | `scoop install fzf` | @@ -173,180 +179,173 @@ On Windows, fzf is available via [Chocolatey][choco], [Scoop][scoop], [winget]: https://github.com/microsoft/winget-pkgs/tree/master/manifests/j/junegunn/fzf [msys2]: https://packages.msys2.org/base/mingw-w64-fzf -### Using git +### 使用 git -Alternatively, you can "git clone" this repository to any directory and run -[install](https://github.com/junegunn/fzf/blob/master/install) script. +或者,你可以将此仓库 "git clone" 到任意目录,然后运行 +[安装](https://github.com/junegunn/fzf/blob/master/install) 脚本。 ```sh git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf ~/.fzf/install ``` -The install script will add lines to your shell configuration file to modify -`$PATH` and set up shell integration. +安装脚本会向你的 shell 配置文件中添加行,以修改 +`$PATH` 并设置 shell 集成。 -### Binary releases +### 二进制发布版 -You can download the official fzf binaries from the releases page. +你可以从发布页面下载官方的 fzf 二进制文件。 * https://github.com/junegunn/fzf/releases -### Setting up shell integration +### 设置 shell 集成 -Add the following line to your shell configuration file. +将以下行添加到你的 shell 配置文件中。 * bash ```sh - # Set up fzf key bindings and fuzzy completion + # 设置 fzf 快捷键和模糊补全 eval "$(fzf --bash)" ``` * zsh ```sh - # Set up fzf key bindings and fuzzy completion + # 设置 fzf 快捷键和模糊补全 source <(fzf --zsh) ``` * fish ```fish - # Set up fzf key bindings + # 设置 fzf 快捷键 fzf --fish | source ``` -* Nushell -- Nushell does not support piping into `source`, so the install - script generates a file in the autoload directory. If you didn't use the - install script, you can manually set it up: +* Nushell——Nushell 不支持将内容管道到 `source`,因此安装 + 脚本会在自动加载目录中生成一个文件。如果你没有使用安装脚本,可以手动设置: ```nu - # Generate the integration script + # 生成集成脚本 mkdir ($nu.default-config-dir | path join "autoload") fzf --nushell | save -f ($nu.default-config-dir | path join "autoload" "_fzf_integration.nu") ``` > [!NOTE] -> `--bash`, `--zsh`, `--fish`, and `--nushell` options are only available in -> recent versions of fzf. If you have an older version of fzf, or want finer control, you can -> source individual script files in the [/shell](/shell) directory. The -> location of the files may vary depending on the package manager you use. -> Please refer to the package documentation for more information. -> (e.g. `apt show fzf`) +> `--bash`、`--zsh`、`--fish` 和 `--nushell` 选项仅适用于 +> 较新版本的 fzf。如果你使用较旧版本的 fzf,或希望进行更精细的控制,可以 +> 引用 [/shell](/shell) 目录中的各个脚本文件。这些 +> 文件的位置可能因你所用的包管理器而异。 +> 请参阅包文档以获取更多信息。 +> (例如 `apt show fzf`) > [!TIP] -> You can disable CTRL-T, CTRL-R, or ALT-C bindings by setting the -> corresponding `*_COMMAND` variable to an empty string when sourcing the -> script. For example, to disable CTRL-R and ALT-C: +> 你可以通过在引用脚本时,将对应的 `*_COMMAND` 变量设为空字符串来禁用 +> CTRL-T、CTRL-R 或 ALT-C 快捷键。例如,禁用 CTRL-R 和 ALT-C: > -> * bash: `FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --bash)"` -> * zsh: `FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source <(fzf --zsh)` -> * fish: `fzf --fish | FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source` -> * nushell: add to your `env.nu`: +> * bash:`FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --bash)"` +> * zsh:`FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source <(fzf --zsh)` +> * fish:`fzf --fish | FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source` +> * nushell:在你的 `env.nu` 中添加: > `$env.FZF_CTRL_R_COMMAND = ""; $env.FZF_ALT_C_COMMAND = ""` > -> Setting the variables after sourcing the script will have no effect. +> 在引用脚本之后设置变量将不会生效。 -### Vim/Neovim plugin +### Vim/Neovim 插件 -If you use [vim-plug](https://github.com/junegunn/vim-plug), add this to -your Vim configuration file: +如果你使用 [vim-plug](https://github.com/junegunn/vim-plug),),请将以下内容添加到 +你的 Vim 配置文件中: ```vim Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' ``` -* `junegunn/fzf` provides the basic library functions - * `fzf#install()` makes sure that you have the latest binary -* `junegunn/fzf.vim` is [a separate project](https://github.com/junegunn/fzf.vim) - that provides a variety of useful commands +* `junegunn/fzf` 提供基础库函数 + * `fzf#install()` 确保你拥有最新二进制文件 +* `junegunn/fzf.vim` 是[一个独立项目](https://github.com/junegunn/fzf.vim)), + 提供各种有用的命令 -To learn more about the Vim integration, see [README-VIM.md](README-VIM.md). +要了解更多关于 Vim 集成的信息,请参阅 [README-VIM.md](README-VIM.md)。 > [!TIP] -> If you use Neovim and prefer Lua-based plugins, check out -> [fzf-lua](https://github.com/ibhagwan/fzf-lua). +> 如果你使用 Neovim 并偏好基于 Lua 的插件,请查看 +> [fzf-lua](https://github.com/ibhagwan/fzf-lua).) -Upgrading fzf +升级 fzf ------------- -fzf is being actively developed, and you might want to upgrade it once in a -while. Please follow the instruction below depending on the installation -method used. +fzf 正在积极开发中,你可能需要时不时地升级它。请根据你使用的安装方式 +按照以下说明操作。 -- git: `cd ~/.fzf && git pull && ./install` -- brew: `brew update; brew upgrade fzf` -- macports: `sudo port upgrade fzf` -- chocolatey: `choco upgrade fzf` -- vim-plug: `:PlugUpdate fzf` +- git:`cd ~/.fzf && git pull && ./install` +- brew:`brew update; brew upgrade fzf` +- macports:`sudo port upgrade fzf` +- chocolatey:`choco upgrade fzf` +- vim-plug:`:PlugUpdate fzf` -Building fzf +构建 fzf ------------ -See [BUILD.md](BUILD.md). +请参阅 [BUILD.md](BUILD.md)。 -Usage +用法 ----- -fzf will launch interactive finder, read the list from STDIN, and write the -selected item to STDOUT. +fzf 会启动交互式查找器,从 STDIN 读取列表,并将选中的项目写入 STDOUT。 ```sh find * -type f | fzf > selected ``` -Without STDIN pipe, fzf will traverse the file system under the current -directory to get the list of files. +没有 STDIN 管道时,fzf 会遍历当前目录下的文件系统来获取文件列表。 ```sh vim $(fzf) ``` > [!NOTE] -> You can override the default behavior -> * Either by setting `$FZF_DEFAULT_COMMAND` to a command that generates the desired list -> * Or by setting `--walker`, `--walker-root`, and `--walker-skip` options in `$FZF_DEFAULT_OPTS` +> 你可以覆盖默认行为 +> * 要么将 `$FZF_DEFAULT_COMMAND` 设置为一个生成所需列表的命令 +> * 要么在 `$FZF_DEFAULT_OPTS` 中设置 `--walker`、`--walker-root` 和 `--walker-skip` 选项 > [!WARNING] -> A more robust solution would be to use `xargs` but we've presented -> the above as it's easier to grasp +> 更稳健的解决方案是使用 `xargs`,但我们展示 +> 了上述方案,因为它更容易理解 > ```sh > fzf --print0 | xargs -0 -o vim > ``` > [!TIP] -> fzf also has the ability to turn itself into a different process. +> fzf 还能够将自身转换为另一个进程。 > > ```sh > fzf --bind 'enter:become(vim {})' > ``` > -> *See [Turning into a different process](#turning-into-a-different-process) -> for more information.* +> *有关更多信息,请参阅[转换为另一个进程](#turning-into-a-different-process)。* -### Using the finder +### 使用查找器 -- `CTRL-K` / `CTRL-J` (or `CTRL-P` / `CTRL-N`) to move cursor up and down -- `Enter` key to select the item, `CTRL-C` / `CTRL-G` / `ESC` to exit -- On multi-select mode (`-m`), `TAB` and `Shift-TAB` to mark multiple items -- Emacs style key bindings -- Mouse: scroll, click, double-click; shift-click and shift-scroll on - multi-select mode +- `CTRL-K` / `CTRL-J`(或 `CTRL-P` / `CTRL-N`)上下移动光标 +- `Enter` 键选择项目,`CTRL-C` / `CTRL-G` / `ESC` 退出 +- 多选模式(`-m`)下,使用 `TAB` 和 `Shift-TAB` 标记多个项目 +- Emacs 风格快捷键 +- 鼠标:滚动、单击、双击;多选模式下 shift+单击 和 shift+滚动 -### Display modes +### 显示模式 -fzf by default runs in fullscreen mode, but there are other display modes. +fzf 默认以全屏模式运行,但也有其他显示模式。 -#### `--height` mode +#### `--height` 模式 -With `--height HEIGHT[%]`, fzf will start below the cursor with the given height. +使用 `--height HEIGHT[%]`,fzf 将在光标下方以指定高度启动。 ```sh fzf --height 40% ``` -`reverse` layout and `--border` goes well with this option. +`reverse` 布局和 `--border` 与此选项搭配效果良好。 ```sh fzf --height 40% --layout reverse --border ``` -By prepending `~` to the height, you're setting the maximum height. +在高度前加上 `~`,可以设置最大高度。 ```sh # Will take as few lines as possible to display the list @@ -354,17 +353,17 @@ seq 3 | fzf --height ~100% seq 3000 | fzf --height ~100% ``` -Height value can be a negative number. +高度值可以是负数。 ```sh # Screen height - 3 fzf --height -3 ``` -#### `--popup` mode +#### `--popup` 模式 -With `--popup` option, fzf will start in a popup window -(requires tmux 3.3+ or Zellij 0.44+). +使用 `--popup` 选项,fzf 将在弹出窗口中启动 +(需要 tmux 3.3+ 或 Zellij 0.44+)。 ```sh # --popup [center|top|bottom|left|right][,SIZE[%]][,SIZE[%][,border-native]] @@ -378,93 +377,88 @@ fzf --popup top,40% # Top, 40% height fzf --popup bottom,80%,40% # Bottom, 80% width, 40% height ``` -`--popup` is silently ignored when you're not on tmux or Zellij. +当你不处于 tmux 或 Zellij 环境中时,`--popup` 会被静默忽略。 > [!NOTE] -> If you're stuck with an old version of tmux that doesn't support popup, -> or if you want to open fzf in a regular tmux pane, check out -> [fzf-tmux](bin/fzf-tmux) script. +> 如果你使用的是不支持弹出窗口的旧版 tmux, +> 或者你想在常规 tmux 窗格中打开 fzf,请查看 +> [fzf-tmux](bin/fzf-tmux) 脚本。 > [!TIP] -> You can add these options to `$FZF_DEFAULT_OPTS` so that they're applied by -> default. For example, +> 你可以将这些选项添加到 `$FZF_DEFAULT_OPTS` 中,以便默认应用它们。 +> 例如, > > ```sh -> # Open in a popup if on tmux or Zellij, otherwise use --height mode +> # 如果在 tmux 或 Zellij 中则在弹出窗口中打开,否则使用 --height 模式 > export FZF_DEFAULT_OPTS='--height 40% --popup bottom,40% --layout reverse --border top' > ``` -### Search syntax +### 搜索语法 -Unless otherwise specified, fzf starts in "extended-search mode" where you can -type in multiple search terms delimited by spaces. e.g. `^music .mp3$ sbtrkt +除非另有指定,fzf 以"扩展搜索模式"启动,你可以输入多个以空格分隔的搜索词。例如 `^music .mp3$ sbtrkt !fire` -| Token | Match type | Description | -| --------- | -------------------------------------- | ------------------------------------------ | -| `sbtrkt` | fuzzy-match | Items that match `sbtrkt` | -| `'wild` | exact-match (quoted) | Items that include `wild` | -| `'wild'` | exact-boundary-match (quoted both ends) | Items that include `wild` at word boundaries | -| `^music` | prefix-exact-match | Items that start with `music` | -| `.mp3$` | suffix-exact-match | Items that end with `.mp3` | -| `!fire` | inverse-exact-match | Items that do not include `fire` | -| `!^music` | inverse-prefix-exact-match | Items that do not start with `music` | -| `!.mp3$` | inverse-suffix-exact-match | Items that do not end with `.mp3` | +| 标记 | 匹配类型 | 描述 | +| --------- | -------------------------------------- | ------------------------------------------ | +| `sbtrkt` | 模糊匹配 | 匹配 `sbtrkt` 的项目 | +| `'wild` | 精确匹配(带引号) | 包含 `wild` 的项目 | +| `'wild'` | 精确边界匹配(两端均带引号) | 在单词边界处包含 `wild` 的项目 | +| `^music` | 前缀精确匹配 | 以 `music` 开头的项目 | +| `.mp3$` | 后缀精确匹配 | 以 `.mp3` 结尾的项目 | +| `!fire` | 反向精确匹配 | 不包含 `fire` 的项目 | +| `!^music` | 反向前缀精确匹配 | 不以 `music` 开头的项目 | +| `!.mp3$` | 反向后缀精确匹配 | 不以 `.mp3` 结尾的项目 | -If you don't prefer fuzzy matching and do not wish to "quote" every word, -start fzf with `-e` or `--exact` option. Note that when `--exact` is set, -`'`-prefix "unquotes" the term. +如果你不喜欢模糊匹配且不希望给每个词加引号, +请使用 `-e` 或 `--exact` 选项启动 fzf。注意,当设置了 +`--exact` 时,`'` 前缀会"取消引号"该词条。 -A single bar character term acts as an OR operator. For example, the following -query matches entries that start with `core` and end with either `go`, `rb`, -or `py`. +单个竖线字符词条充当 OR 运算符。例如,以下查询匹配以 `core` 开头 +且以 `go`、`rb` 或 `py` 结尾的条目。 ``` ^core go$ | rb$ | py$ ``` -### Environment variables +### 环境变量 - `FZF_DEFAULT_COMMAND` - - Default command to use when input is tty - - e.g. `export FZF_DEFAULT_COMMAND='fd --type f'` + - 当输入为 tty 时使用的默认命令 + - 例如 `export FZF_DEFAULT_COMMAND='fd --type f'` - `FZF_DEFAULT_OPTS` - - Default options - - e.g. `export FZF_DEFAULT_OPTS="--layout=reverse --inline-info"` + - 默认选项 + - 例如 `export FZF_DEFAULT_OPTS="--layout=reverse --inline-info"` - `FZF_DEFAULT_OPTS_FILE` - - If you prefer to manage default options in a file, set this variable to - point to the location of the file - - e.g. `export FZF_DEFAULT_OPTS_FILE=~/.fzfrc` + - 如果你更倾向于在文件中管理默认选项,请将此变量设置为 + 指向该文件的位置 + - 例如 `export FZF_DEFAULT_OPTS_FILE=~/.fzfrc` > [!WARNING] -> `FZF_DEFAULT_COMMAND` is not used by shell integration due to the -> slight difference in requirements. +> `FZF_DEFAULT_COMMAND` 未被 shell 集成使用,因为需求略有差异。 > -> * `CTRL-T` runs `$FZF_CTRL_T_COMMAND` to get a list of files and directories -> * `ALT-C` runs `$FZF_ALT_C_COMMAND` to get a list of directories -> * `vim ~/**` runs `fzf_compgen_path()` with the prefix (`~/`) as the first argument -> * `cd foo**` runs `fzf_compgen_dir()` with the prefix (`foo`) as the first argument +> * `CTRL-T` 运行 `$FZF_CTRL_T_COMMAND` 以获取文件和目录列表 +> * `ALT-C` 运行 `$FZF_ALT_C_COMMAND` 以获取目录列表 +> * `vim ~/**` 以前缀(`~/`)作为第一个参数运行 `fzf_compgen_path()` +> * `cd foo**` 以前缀(`foo`)作为第一个参数运行 `fzf_compgen_dir()` > -> The available options are described later in this document. +> 可用选项详见本文档后续内容。 -### Customizing the look +### 自定义外观 -The user interface of fzf is fully customizable with a large number of -configuration options. For a quick setup, you can start with one of the style -presets -- `default`, `full`, or `minimal` -- using the `--style` option. +fzf 的用户界面可通过大量配置选项进行完全自定义。如需快速设置,你可以使用 `default`、`full` 或 `minimal` 等样式预设之一,通过 `--style` 选项启动。 ```sh fzf --style full \ --preview 'fzf-preview.sh {}' --bind 'focus:transform-header:file --brief {}' ``` -| Preset | Screenshot | +| 预设 | 截图 | | :--- | :--- | | `default` | | | `full` | | | `minimal` | | -Here's an example based on the `full` preset: +以下是一个基于 `full` 预设的示例: @@ -494,104 +488,94 @@ git ls-files | fzf --style full \ -### Options +### 选项 -See the man page (`fzf --man` or `man fzf`) for the full list of options. +请查阅手册(`fzf --man` 或 `man fzf`)获取完整选项列表。 -### Demo -If you learn by watching videos, check out this screencast by [@samoshkin](https://github.com/samoshkin) to explore `fzf` features. +### 演示 +如果你喜欢通过视频学习,可以观看 [@samoshkin](https://github.com/samoshkin)) 制作的这个录屏,探索 `fzf` 的各项功能。 - + -Examples +示例 -------- -* [Wiki page of examples](https://github.com/junegunn/fzf/wiki/examples) - * *Disclaimer: The examples on this page are maintained by the community - and are not thoroughly tested* -* [Advanced fzf examples](https://github.com/junegunn/fzf/blob/master/ADVANCED.md) +* [示例 Wiki 页面](https://github.com/junegunn/fzf/wiki/examples)) + * *免责声明:该页面上的示例由社区维护,未经全面测试* +* [高级 fzf 示例](https://github.com/junegunn/fzf/blob/master/ADVANCED.md)) -Key bindings for command-line +命令行按键绑定 ----------------------------- -By [setting up shell integration](#setting-up-shell-integration), you can use -the following key bindings in bash, zsh, fish, and Nushell. +通过[设置 shell 集成](#setting-up-shell-integration),你可以在 bash、zsh、fish 和 Nushell 中使用以下按键绑定。 -- `CTRL-T` - Paste the selected files and directories onto the command-line - - The list is generated using `--walker file,dir,follow,hidden` option - - You can override the behavior by setting `FZF_CTRL_T_COMMAND` to a custom command that generates the desired list - - Or you can set `--walker*` options in `FZF_CTRL_T_OPTS` - - Set `FZF_CTRL_T_OPTS` to pass additional options to fzf +- `CTRL-T` - 将选中的文件和目录粘贴到命令行中 + - 列表通过 `--walker file,dir,follow,hidden` 选项生成 + - 你可以通过设置 `FZF_CTRL_T_COMMAND` 为自定义命令来覆盖默认行为 + - 或者你可以在 `FZF_CTRL_T_OPTS` 中设置 `--walker*` 选项 + - 设置 `FZF_CTRL_T_OPTS` 以向 fzf 传递额外选项 ```sh - # Preview file content using bat (https://github.com/sharkdp/bat) + # 使用 bat 预览文件内容(https://github.com/sharkdp/bat)) export FZF_CTRL_T_OPTS=" --walker-skip .git,node_modules,target --preview 'bat -n --color=always {}' --bind 'ctrl-/:change-preview-window(down|hidden|)'" ``` - - Can be disabled by setting `FZF_CTRL_T_COMMAND` to an empty string when - sourcing the script -- `CTRL-R` - Paste the selected command from history onto the command-line. - - Select multiple commands with `TAB`. - - If you want to see the commands in chronological order, press `CTRL-R` - again which toggles sorting by relevance - - Press `ALT-R` to toggle "raw" mode where you can see the surrounding items - of a match. In this mode, you can press `CTRL-N` and `CTRL-P` to move - between the matching items only. - - Press `CTRL-/` or `ALT-/` to toggle line wrapping - - Press `SHIFT-DELETE` to delete the selected commands (bash and fish) - - Fish shell only: - - Press `ALT-ENTER` to reformat and insert the selected commands - - Press `ALT-T` to cycle through command prefix (timestamp, date/time, none) - - Set `FZF_CTRL_R_OPTS` to pass additional options to fzf + - 可以通过在加载脚本时将 `FZF_CTRL_T_COMMAND` 设为空字符串来禁用 +- `CTRL-R` - 将选中的历史命令粘贴到命令行中。 + - 使用 `TAB` 选择多条命令。 + - 如果想按时间顺序查看命令,再次按下 `CTRL-R` 可切换为按相关性排序 + - 按下 `ALT-R` 切换"原始"模式,可查看匹配项周围的上下文。在该模式下,按下 `CTRL-N` 和 `CTRL-P` 仅在匹配项之间移动。 + - 按下 `CTRL-/` 或 `ALT-/` 切换自动换行 + - 按下 `SHIFT-DELETE` 删除选中的命令(bash 和 fish) + - 仅限 Fish shell: + - 按下 `ALT-ENTER` 重新格式化并插入选中的命令 + - 按下 `ALT-T` 循环切换命令前缀(时间戳、日期/时间、无) + - 设置 `FZF_CTRL_R_OPTS` 以向 fzf 传递额外选项 ```sh - # CTRL-Y to copy the command into clipboard using pbcopy + # CTRL-Y 使用 pbcopy 将命令复制到剪贴板 export FZF_CTRL_R_OPTS=" --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --color header:italic --header 'Press CTRL-Y to copy command into clipboard'" ``` ```fish - # Fish shell: Set date/time as default prefix + # Fish shell:设置日期/时间为默认前缀 set -gx FZF_CTRL_R_OPTS "--with-nth 1,3.. --bind 'alt-t:change-with-nth(2..|3..|1,3..)'" - # Or display no prefix by default + # 或默认不显示前缀 set -gx FZF_CTRL_R_OPTS "--with-nth 3.. --bind 'alt-t:change-with-nth(2..|1,3..|3..)'" ``` - - Can be disabled by setting `FZF_CTRL_R_COMMAND` to an empty string when - sourcing the script - - Custom override via a non-empty `FZF_CTRL_R_COMMAND` is not yet supported and will emit a warning -- `ALT-C` - cd into the selected directory - - The list is generated using `--walker dir,follow,hidden` option - - Set `FZF_ALT_C_COMMAND` to override the default command - - Or you can set `--walker-*` options in `FZF_ALT_C_OPTS` - - Set `FZF_ALT_C_OPTS` to pass additional options to fzf + - 可以通过在加载脚本时将 `FZF_CTRL_R_COMMAND` 设为空字符串来禁用 + - 通过非空的 `FZF_CTRL_R_COMMAND` 进行自定义覆盖暂不支持,会发出警告 +- `ALT-C` - 进入选中的目录 + - 列表通过 `--walker dir,follow,hidden` 选项生成 + - 设置 `FZF_ALT_C_COMMAND` 以覆盖默认命令 + - 或者你可以在 `FZF_ALT_C_OPTS` 中设置 `--walker-*` 选项 + - 设置 `FZF_ALT_C_OPTS` 以向 fzf 传递额外选项 ```sh - # Print tree structure in the preview window + # 在预览窗口中打印树形结构 export FZF_ALT_C_OPTS=" --walker-skip .git,node_modules,target --preview 'tree -C {}'" ``` - - Can be disabled by setting `FZF_ALT_C_COMMAND` to an empty string when - sourcing the script + - 可以通过在加载脚本时将 `FZF_ALT_C_COMMAND` 设为空字符串来禁用 -Display modes for these bindings can be separately configured via -`FZF_{CTRL_T,CTRL_R,ALT_C}_OPTS` or globally via `FZF_DEFAULT_OPTS`. -(e.g. `FZF_CTRL_R_OPTS='--popup bottom,60% --height 60% --border top'`) +这些绑定的显示模式可通过 `FZF_{CTRL_T,CTRL_R,ALT_C}_OPTS` 单独配置,或通过 `FZF_DEFAULT_OPTS` 全局配置。 +(例如:`FZF_CTRL_R_OPTS='--popup bottom,60% --height 60% --border top'`) -More tips can be found on [the wiki page](https://github.com/junegunn/fzf/wiki/Configuring-shell-key-bindings). +更多技巧请参见 [Wiki 页面](https://github.com/junegunn/fzf/wiki/Configuring-shell-key-bindings).) -Fuzzy completion +模糊补全 ---------------- -Shell integration also provides fuzzy completion for bash, zsh, fish, and Nushell. +Shell 集成还为 bash、zsh、fish 和 Nushell 提供了模糊补全功能。 -### Files and directories +### 文件和目录 -Fuzzy completion for files and directories can be triggered if the word before -the cursor ends with the trigger sequence, which is by default `**`. +如果光标前的单词以触发序列结尾(默认为 `**`),则可触发文件和目录的模糊补全。 - `COMMAND [DIRECTORY/][FUZZY_PATTERN]**` @@ -617,25 +601,24 @@ cd ** cd ~/github/fzf** ``` -### Process IDs +### 进程 ID -Fuzzy completion for PIDs is provided for kill command. +为 kill 命令提供了 PID 的模糊补全。 ```sh # Can select multiple processes with or keys kill -9 ** ``` -### Host names +### 主机名 -For ssh command, fuzzy completion for hostnames is provided. The names are -extracted from /etc/hosts and ~/.ssh/config. +为 ssh 命令提供了主机名的模糊补全。主机名从 /etc/hosts 和 ~/.ssh/config 中提取。 ```sh ssh ** ``` -### Environment variables / Aliases +### 环境变量 / 别名 ```sh # bash and zsh @@ -647,9 +630,9 @@ unalias ** set ``` -### Customizing fuzzy completion for bash and zsh +### 自定义 bash 和 zsh 的模糊补全 -#### Customizing fzf options for completion +#### 自定义补全的 fzf 选项 ```sh # Use ~~ as the trigger sequence instead of the default ** @@ -680,7 +663,7 @@ _fzf_comprun() { } ``` -#### Customizing completion source for paths and directories +#### 自定义路径和目录的补全来源 ```sh # Use fd (https://github.com/sharkdp/fd) for listing path candidates. @@ -696,11 +679,11 @@ _fzf_compgen_dir() { } ``` -#### Supported commands (bash) +#### 支持的命令(bash) -On bash, fuzzy completion is enabled only for a predefined set of commands -(`complete | grep _fzf` to see the list). But you can enable it for other -commands as well by using `_fzf_setup_completion` helper function. +在 bash 中,模糊补全仅对预定义的命令集生效 +(可通过 ``complete | grep _fzf`` 查看列表)。但你也可以使用 +``_fzf_setup_completion`` 辅助函数为其他命令启用模糊补全。 ```sh # usage: _fzf_setup_completion path|dir|var|alias|host COMMANDS... @@ -708,12 +691,12 @@ _fzf_setup_completion path ag git kubectl _fzf_setup_completion dir tree ``` -#### Custom fuzzy completion +#### 自定义模糊补全 -_**(Custom completion API is experimental and subject to change)**_ +_**(自定义补全 API 处于实验阶段,可能发生变更)**_ -For a command named _"COMMAND"_, define `_fzf_complete_COMMAND` function using -`_fzf_complete` helper. +对于名为 _"COMMAND"_ 的命令,使用 ``_fzf_complete`` 辅助函数定义 +``_fzf_complete_COMMAND`` 函数。 ```sh # Custom fuzzy completion for "doge" command @@ -728,21 +711,20 @@ _fzf_complete_doge() { } ``` -- The arguments before `--` are the options to fzf. -- After `--`, simply pass the original completion arguments unchanged (`"$@"`). -- Then, write a set of commands that generates the completion candidates and - feed its output to the function using process substitution (`< <(...)`). +- ``--`` 之前的参数是传递给 fzf 的选项。 +- ``--`` 之后,只需原封不动地传递原始的补全参数(``"$@"``)。 +- 然后,编写一组命令来生成补全候选,并通过进程替换(``< <(...)``) + 将其输出送入该函数。 -zsh will automatically pick up the function using the naming convention but in -bash you have to manually associate the function with the command using the -`complete` command. +zsh 会根据命名约定自动识别该函数,但在 bash 中,你需要使用 +``complete`` 命令手动将函数与命令关联。 ```sh [ -n "$BASH" ] && complete -F _fzf_complete_doge -o default -o bashdefault doge ``` -If you need to post-process the output from fzf, define -`_fzf_complete_COMMAND_post` as follows. +如果你需要对 fzf 的输出进行后处理,可以按如下方式定义 +``_fzf_complete_COMMAND_post``。 ```sh _fzf_complete_foo() { @@ -758,33 +740,28 @@ _fzf_complete_foo_post() { [ -n "$BASH" ] && complete -F _fzf_complete_foo -o default -o bashdefault foo ``` -### Fuzzy completion for fish +### Fish 的模糊补全 -Fuzzy completion for fish differs from bash and zsh in that: +Fish 的模糊补全与 bash 和 zsh 的区别在于: -- It doesn't require a trigger sequence like `**`. Instead, if activates - on `Shift-TAB` (replacing the native pager search mode), while `TAB` preserves - fish's native completion behavior. -- It relies on fish's native completion system to populate the candidate list, - rather than performing a recursive file system traversal. For recursive - searching, use the `CTRL-T` binding instead. -- If the current command line token is a wildcard pattern, it performs search on - the wildcard expansion path list (instead of the native behavior of inserting - all the results in command line). Because the shell is used for the expansion, - there is a limit in the number of results. -- The only supported configuration variables are `FZF_COMPLETION_OPTS` and - `FZF_EXPANSION_OPS`. -- The function that is used by custom completion functions is named - `fzf_complete`, which only accepts fzf options as arguments, and can be also - called without any redirected input, to just modify fzf options while - presenting the native completion results. For compatibility with other shells, - a function named `_fzf_complete` is provided, that can accept ` -- $argv` in - its command line arguments, after fzf options. +- 它不需要像 ``**`` 这样的触发序列。相反,它在 + ``Shift-TAB`` 上激活(替代原生分页器搜索模式),而 ``TAB`` 保留 + fish 的原生补全行为。 +- 它依赖 fish 的原生补全系统来生成候选列表,而非执行递归的文件系统遍历。如需递归搜索, + 请改用 ``CTRL-T`` 绑定。 +- 如果当前命令行令牌是通配符模式,它会在通配符展开路径列表上执行搜索(而非将 + 所有结果插入命令行的原生行为)。由于展开由 shell 执行,结果数量存在上限。 +- 仅支持的配置变量是 ``FZF_COMPLETION_OPTS`` 和 + ``FZF_EXPANSION_OPS``。 +- 自定义补全函数所使用的函数名为 + ``fzf_complete``,它只接受 fzf 选项作为参数,也可以在没有任何重定向输入的情况下调用, + 仅用于修改 fzf 选项同时呈现原生补全结果。为了与其他 shell 兼容, + 提供了名为 ``_fzf_complete`` 的函数,它在 fzf 选项之后可以接受命令行参数中的 + `` -- $argv``。 -For commands that are not covered by fish completions, it is better to create -regular fish completion functions (which will work for both `TAB` and -`Shift-TAB`), and create fzf completion functions only when needing to modify -fzf options for a specific command or want different results for `Shift-TAB`: +对于 fish 补全覆盖不到的命令,最好创建常规的 fish 补全函数(这对 ``TAB`` 和 +``Shift-TAB`` 都有效),并仅在需要修改特定命令的 fzf 选项或希望 ``Shift-TAB`` +获得不同结果时才创建 fzf 补全函数: ```fish # Customize git completion @@ -819,9 +796,8 @@ function _fzf_complete_git end ``` -Similar to bash and zsh, the output of fzf can be processed before inserted in -command line, by defining a function named `_fzf_complete_COMMAND_post` or -`_fzf_post_complete_COMMAND`: +与 bash 和 zsh 类似,可以通过定义一个名为 ``_fzf_complete_COMMAND_post`` 或 +``_fzf_post_complete_COMMAND`` 的函数来对 fzf 的输出进行处理后再插入命令行: ```fish function _fzf_complete_foo @@ -835,19 +811,16 @@ function _fzf_post_complete_foo end ``` -### Fuzzy completion for Nushell +### Nushell 的模糊补全 -Fuzzy completion in Nushell works via the -[external completer](https://www.nushell.sh/cookbook/external_completers.html) -mechanism. There are some differences compared to bash and zsh: +Nushell 中的模糊补全通过 +[外部补全器](https://www.nushell.sh/cookbook/external_completers.html)) +机制实现。与 bash 和 zsh 相比存在一些差异: -- On Nushell >= 0.103.0, the external completer is no longer called for - built-in commands (e.g. `cd`, `ls`). Fuzzy completion with `**` only - works for external commands. -- Custom completers can be defined via the `$env.FZF_COMPLETERS` record in - your `config.nu`. Each entry is a closure that receives the prefix and the - command spans, and returns either a list of candidate strings or a record - `{ candidates: [...], opts: [...] }` for custom fzf options: +- 在 Nushell >= 0.103.0 上,内置命令(例如 ``cd``、``ls``)不再调用外部补全器。使用 ``**`` 的模糊补全仅对外部命令生效。 +- 自定义补全器可以通过 ``$env.FZF_COMPLETERS`` 记录在你的 + ``config.nu`` 中定义。每个条目是一个闭包,接收前缀和命令跨度,返回候选字符串列表或包含自定义 fzf 选项的记录 + ``{ candidates: [...], opts: [...] }``: ```nu $env.FZF_COMPLETERS = { pacman: {|prefix, spans| @@ -859,229 +832,187 @@ mechanism. There are some differences compared to bash and zsh: } } ``` - See [shell/completion-examples.nu](shell/completion-examples.nu) for more - examples. -- The following environment variables are supported: - `FZF_COMPLETION_TRIGGER`, `FZF_COMPLETION_OPTS`, - `FZF_COMPLETION_PATH_OPTS`, `FZF_COMPLETION_DIR_OPTS`, - `FZF_COMPLETION_DIR_COMMANDS`. + 更多示例请参见 [shell/completion-examples.nu](shell/completion-examples.nu)。 +- 支持以下环境变量: + ``FZF_COMPLETION_TRIGGER``、``FZF_COMPLETION_OPTS``、 + ``FZF_COMPLETION_PATH_OPTS``、``FZF_COMPLETION_DIR_OPTS``、 + ``FZF_COMPLETION_DIR_COMMANDS``。 -Vim plugin +Vim 插件 ---------- -See [README-VIM.md](README-VIM.md). +参见 [README-VIM.md](README-VIM.md)。 -Advanced topics +高级主题 --------------- -### Customizing for different types of input +### 针对不同类型输入的自定义 -Since fzf is a general-purpose text filter, its algorithm was designed to -"generally" work well with any kind of input. However, admittedly, there is no -true one-size-fits-all solution, and you may want to tweak the algorithm and -some of the settings depending on the type of the input. To make this process -easier, fzf provides a set of "scheme"s for some common input types. +由于 fzf 是一个通用的文本过滤器,其算法设计为"一般"能很好地适用于任何类型的输入。但不可否认,没有真正通用的解决方案,你可能需要根据输入类型调整算法和一些设置。为简化这一过程,fzf 为几种常见输入类型提供了一套"方案"。 -| Scheme | Description | +| 方案 | 描述 | | :--- | :--- | -| `--scheme=default` | Generic scheme designed to work well with any kind of input | -| `--scheme=path` | Suitable for file paths | -| `--scheme=history` | Suitable for command history or any input where chronological ordering is important | +| ``--scheme=default`` | 通用方案,设计为能很好地适用于任何类型的输入 | +| ``--scheme=path`` | 适用于文件路径 | +| ``--scheme=history`` | 适用于命令历史或任何按时间顺序排列重要的输入 | -(See `fzf --man` for the details) +(详见 ``fzf --man``) -### Performance +### 性能 -fzf is fast. Performance should not be a problem in most use cases. However, -you might want to be aware of the options that can affect performance. +fzf 很快。在大多数使用场景中性能不应成为问题。不过,你可能需要注意那些会影响性能的选项。 -- `--ansi` tells fzf to extract and parse ANSI color codes in the input, and it - makes the initial scanning slower. So it's not recommended that you add it - to your `$FZF_DEFAULT_OPTS`. -- `--nth` makes fzf slower because it has to tokenize each line. -- A plain string `--delimiter` should be preferred over a regular expression - delimiter. -- `--with-nth` makes fzf slower as fzf has to tokenize and reassemble each - line. +- ``--ansi`` 告知 fzf 提取并解析输入中的 ANSI 颜色代码,这会使初始扫描变慢。因此不建议将其加入 ``$FZF_DEFAULT_OPTS``。 +- ``--nth`` 会使 fzf 变慢,因为它需要对每一行进行分词。 +- 纯字符串 ``--delimiter`` 应优先于正则表达式分隔符。 +- ``--with-nth`` 会使 fzf 变慢,因为它需要对每一行进行分词并重新组装。 -### Executing external programs +### 执行外部程序 -You can set up key bindings for starting external processes without leaving -fzf (`execute`, `execute-silent`). +你可以设置按键绑定,在不离开 fzf 的情况下启动外部进程(``execute``、``execute-silent``)。 -```bash +````bash # Press F1 to open the file with less without leaving fzf # Press CTRL-Y to copy the line to clipboard and aborts fzf (requires pbcopy) fzf --bind 'f1:execute(less -f {}),ctrl-y:execute-silent(echo {} | pbcopy)+abort' -``` +```` -See *KEY/EVENT BINDINGS* section of the man page for details. +详情请参阅手册的*按键/事件绑定*章节。 -### Turning into a different process +### 切换为另一个进程 -`become(...)` is similar to `execute(...)`/`execute-silent(...)` described -above, but instead of executing the command and coming back to fzf on -complete, it turns fzf into a new process for the command. +``become(...)`` 与上文介绍的 ``execute(...)``/``execute-silent(...)`` 类似,不同之处在于它不会执行命令后返回 fzf,而是将 fzf 切换为执行该命令的新进程。 -```sh +````sh fzf --bind 'enter:become(vim {})' -``` +```` -Compared to the seemingly equivalent command substitution `vim "$(fzf)"`, this -approach has several advantages: +与看似等效的命令替换 ``vim "$(fzf)"`` 相比,这种方式有几个优势: -* Vim will not open an empty file when you terminate fzf with - CTRL-C -* Vim will not open an empty file when you press ENTER on an empty - result -* Can handle multiple selections even when they have whitespaces +* 当用 CTRL-C 终止 fzf 时,Vim 不会打开空文件 +* 当在空结果上按 ENTER 时,Vim 不会打开空文件 +* 可以处理多项选择,即使其中包含空格 ```sh fzf --multi --bind 'enter:become(vim {+})' ``` -To be fair, running `fzf --print0 | xargs -0 -o vim` instead of `vim "$(fzf)"` -resolves all of the issues mentioned. Nonetheless, `become(...)` still offers -additional benefits in different scenarios. +公平地说,使用 ``fzf --print0 | xargs -0 -o vim`` 代替 ``vim "$(fzf)"`` 可以解决上述所有问题。尽管如此,``become(...)`` 在不同场景下仍提供了额外优势。 -* You can set up multiple bindings to handle the result in different ways - without any wrapping script +* 你可以设置多个绑定,以不同方式处理结果,而无需任何包装脚本 ```sh fzf --bind 'enter:become(vim {}),ctrl-e:become(emacs {})' ``` - * Previously, you would have to use `--expect=ctrl-e` and check the first - line of the output of fzf -* You can easily build the subsequent command using the field index - expressions of fzf + * 之前,你需要使用 ``--expect=ctrl-e`` 并检查 fzf 输出的第一行 +* 你可以利用 fzf 的字段索引表达式轻松构建后续命令 ```sh - # Open the file in Vim and go to the line + # 在 Vim 中打开文件并跳转到指定行 git grep --line-number . | fzf --delimiter : --nth 3.. --bind 'enter:become(vim {1} +{2})' ``` -### Reloading the candidate list +### 重新加载候选列表 -By binding `reload` action to a key or an event, you can make fzf dynamically -reload the candidate list. See https://github.com/junegunn/fzf/issues/1750 for -more details. +通过将 ``reload`` 操作绑定到某个按键或事件,你可以让 fzf 动态重新加载候选列表。详情请参见 `https://github.com/junegunn/fzf/issues/1750`。 -#### 1. Update the list of processes by pressing CTRL-R +#### 1. 按 CTRL-R 更新进程列表 -```sh +````sh ps -ef | fzf --bind 'ctrl-r:reload(ps -ef)' \ --header 'Press CTRL-R to reload' --header-lines=1 \ --height=50% --layout=reverse -``` +```` -#### 2. Switch between sources by pressing CTRL-D or CTRL-F +#### 2. 按 CTRL-D 或 CTRL-F 切换源 -```sh +````sh FZF_DEFAULT_COMMAND='find . -type f' \ fzf --bind 'ctrl-d:reload(find . -type d),ctrl-f:reload(eval "$FZF_DEFAULT_COMMAND")' \ --height=50% --layout=reverse -``` +```` -#### 3. Interactive ripgrep integration +#### 3. 交互式 ripgrep 集成 -The following example uses fzf as the selector interface for ripgrep. We bound -`reload` action to `change` event, so every time you type on fzf, the ripgrep -process will restart with the updated query string denoted by the placeholder -expression `{q}`. Also, note that we used `--disabled` option so that fzf -doesn't perform any secondary filtering. +以下示例将 fzf 作为 ripgrep 的选择器界面。我们将 ``reload`` 操作绑定到 ``change`` 事件,这样每当你在 fzf 中输入时,ripgrep 进程都会重新启动,并使用占位符表达式 ``{q}`` 表示更新后的查询字符串。另外,注意我们使用了 ``--disabled`` 选项,使 fzf 不执行任何二次过滤。 -```sh +````sh : | rg_prefix='rg --column --line-number --no-heading --color=always --smart-case' \ fzf --bind 'start:reload:$rg_prefix ""' \ --bind 'change:reload:$rg_prefix {q} || true' \ --bind 'enter:become(vim {1} +{2})' \ --ansi --disabled \ --height=50% --layout=reverse -``` +```` -If ripgrep doesn't find any matches, it will exit with a non-zero exit status, -and fzf will warn you about it. To suppress the warning message, we added -`|| true` to the command, so that it always exits with 0. +如果 ripgrep 没有找到任何匹配项,它将以非零退出码退出,fzf 会对此发出警告。要抑制该警告信息,我们为命令添加了 ``|| true``,使其始终以 0 退出。 -See ["Using fzf as interactive Ripgrep launcher"](https://github.com/junegunn/fzf/blob/master/ADVANCED.md#using-fzf-as-interactive-ripgrep-launcher) -for more sophisticated examples. +更复杂的示例请参见 ["Using fzf as interactive Ripgrep launcher"](`https://github.com/junegunn/fzf/blob/master/ADVANCED.md#using-fzf-as-interactive-ripgrep-launcher)`)。 -### Preview window +### 预览窗口 -When the `--preview` option is set, fzf automatically starts an external process -with the current line as the argument and shows the result in the split window. -Your `$SHELL` is used to execute the command with `$SHELL -c COMMAND`. -The window can be scrolled using the mouse or custom key bindings. +设置 ``--preview`` 选项后,fzf 会自动启动一个外部进程,将当前行作为参数传入,并在拆分窗口中显示结果。你的 ``$SHELL`` 用于执行该命令,``$SHELL -c COMMAND`` 作为参数传入。可以使用鼠标或自定义按键绑定来滚动窗口。 -```bash +````bash # {} is replaced with the single-quoted string of the focused line fzf --preview 'cat {}' -``` +```` -Preview window supports ANSI colors, so you can use any program that -syntax-highlights the content of a file, such as -[Bat](https://github.com/sharkdp/bat) or -[Highlight](https://gitlab.com/saalen/highlight): +预览窗口支持 ANSI 颜色,因此你可以使用任何能够对文件内容进行语法高亮的程序,例如 [Bat](`https://github.com/sharkdp/bat)`) 或 [Highlight](`https://gitlab.com/saalen/highlight):`)。 -```bash +````bash fzf --preview 'bat --color=always {}' --preview-window '~3' -``` +```` -You can customize the size, position, and border of the preview window using -`--preview-window` option, and the foreground and background color of it with -`--color` option. For example, +你可以使用 ``--preview-window`` 选项自定义预览窗口的大小、位置和边框,使用 ``--color`` 选项自定义其前景色和背景色。例如: -```bash +````bash fzf --height 40% --layout reverse --info inline --border \ --preview 'file {}' --preview-window up,1,border-horizontal \ --bind 'ctrl-/:change-preview-window(50%|hidden|)' \ --color 'fg:#bbccdd,fg+:#ddeeff,bg:#334455,preview-bg:#223344,border:#778899' -``` +```` -See the man page (`man fzf`) for the full list of options. +完整选项列表请参阅手册(``man fzf``)。 -More advanced examples can be found [here](https://github.com/junegunn/fzf/blob/master/ADVANCED.md). +更多高级示例请参见[此处](`https://github.com/junegunn/fzf/blob/master/ADVANCED.md).`)。 > [!WARNING] -> Since fzf is a general-purpose text filter rather than a file finder, **it is -> not a good idea to add `--preview` option to your `$FZF_DEFAULT_OPTS`**. +> 由于 fzf 是通用文本过滤器而非文件查找器,**不建议将 ``--preview`` 选项加入你的 ``$FZF_DEFAULT_OPTS``**。 > > ```sh > # ********************* -> # ** DO NOT DO THIS! ** +> # ** 不要这样做!** > # ********************* > export FZF_DEFAULT_OPTS='--preview "bat --style=numbers --color=always --line-range :500 {}"' > -> # bat doesn't work with any input other than the list of files +> # bat 不适用于除文件列表以外的任何输入 > ps -ef | fzf > seq 100 | fzf > history | fzf > ``` -### Previewing an image +### 预览图片 -fzf can display images in the preview window using one of the following protocols: +fzf 可以通过以下协议之一在预览窗口中显示图片: -* [Kitty graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) -* [iTerm2 inline images protocol](https://iterm2.com/documentation-images.html) -* [Sixel](https://en.wikipedia.org/wiki/Sixel) +* [Kitty 图形协议](`https://sw.kovidgoyal.net/kitty/graphics-protocol/)`) +* [iTerm2 内联图片协议](`https://iterm2.com/documentation-images.html)`) +* [Sixel](`https://en.wikipedia.org/wiki/Sixel)`) -See [bin/fzf-preview.sh](bin/fzf-preview.sh) script for more information. +更多信息请参见 [bin/fzf-preview.sh](bin/fzf-preview.sh) 脚本。 -```sh +````sh fzf --preview 'fzf-preview.sh {}' -``` +```` -Tips +技巧 ---- -### Respecting `.gitignore` +### 遵守 ``.gitignore`` -You can use [fd](https://github.com/sharkdp/fd), -[ripgrep](https://github.com/BurntSushi/ripgrep), or [the silver -searcher](https://github.com/ggreer/the_silver_searcher) to traverse the file -system while respecting `.gitignore`. +你可以使用 [fd](`https://github.com/sharkdp/fd),`)、[ripgrep](`https://github.com/BurntSushi/ripgrep),`) 或 [The Silver Searcher](`https://github.com/ggreer/the_silver_searcher)`) 来遍历文件系统,同时遵守 ``.gitignore``。 -```sh +````sh # Feed the output of fd into fzf fd --type f --strip-cwd-prefix | fzf @@ -1093,61 +1024,54 @@ fzf # To apply the command to CTRL-T as well export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" -``` +```` -If you want the command to follow symbolic links and don't want it to exclude -hidden files, use the following command: +如果你希望命令跟随符号链接且不排除隐藏文件,请使用以下命令: -```sh +````sh export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix --hidden --follow --exclude .git' -``` +```` ### Fish shell -`CTRL-T` key binding of fish, unlike those of bash and zsh, will use the last -token on the command-line as the root directory for the recursive search. For -instance, hitting `CTRL-T` at the end of the following command-line +与 bash 和 zsh 不同,fish 的 ``CTRL-T`` 按键绑定会将命令行上的最后一个 token 作为递归搜索的根目录。例如,在以下命令行的末尾按下 ``CTRL-T``: -```sh +````sh ls /var/ -``` +```` -will list all files and directories under `/var/`. +将列出 ``/var/`` 下的所有文件和目录。 -When using a custom `FZF_CTRL_T_COMMAND`, use the unexpanded `$dir` variable to -make use of this feature. `$dir` defaults to `.` when the last token is not a -valid directory. Example: +使用自定义 ``FZF_CTRL_T_COMMAND`` 时,请使用未展开的 ``$dir`` 变量来利用此功能。当最后一个 token 不是有效目录时,``$dir`` 默认为 ``.``。示例: -```sh +````sh set -g FZF_CTRL_T_COMMAND "command find -L \$dir -type f 2> /dev/null | sed '1d; s#^\./##'" -``` +```` -### fzf Theme Playground +### fzf 主题游乐场 -[fzf Theme Playground](https://vitormv.github.io/fzf-themes/) created by -[Vitor Mello](https://github.com/vitormv) is a webpage where you can -interactively create fzf themes. +[fzf 主题游乐场](`https://vitormv.github.io/fzf-themes/)`) 由 [Vitor Mello](`https://github.com/vitormv)`) 创建,是一个可以交互式创建 fzf 主题的网页。 -Related projects ----------------- +相关项目 +-------- -https://github.com/junegunn/fzf/wiki/Related-projects +`https://github.com/junegunn/fzf/wiki/Related-projects` [License](LICENSE) ------------------ -The MIT License (MIT) +MIT 许可证 (MIT) Copyright (c) 2013-2026 Junegunn Choi Goods ----- -Grab fzf T-shirts, mugs, and stickers here: https://commitgoods.com/collections/fzf +在此获取 fzf T 恤、马克杯和贴纸:https://commitgoods.com/collections/fzf Sponsors :heart: ---------------- -I would like to thank all the sponsors of this project who make it possible for me to continue to improve fzf. +我要感谢本项目的所有赞助商,是他们让我能够继续改进 fzf。 -If you'd like to sponsor this project, please visit https://github.com/sponsors/junegunn. +如果你想赞助本项目,请访问 https://github.com/sponsors/junegunn.