fzf模糊搜索神器的安裝和使用
fzf是一個通用的命令行模糊查找器, 通過輸入模糊的關鍵詞就可以定位文件或文件夾。結合其他工具(比如rg)可以完成非常多的工作,在工作中可以大幅提高你的工作效率。
fzf可以用於文件、命令歷史記錄、進程、主機名、書簽、git提交等。
1. fzf使用
1.1 安裝
Using Homebrew
You can use Homebrew (on macOS or Linux) to install fzf.
brew install fzf
# To install useful key bindings and fuzzy completion: $(brew --prefix)/opt/fzf/install
1.2 使用
安裝后, 可以執行下fzf, 先體驗下, 另外 fzf 重寫了 ctrl+r 搜索歷史命令

vim $(fzf) # 搜索后, 回車直接用 vi 打開 |
-
搜索過程中, CTRL-J 和 CTRL-K 向上翻和向下翻
-
bash和zsh的模糊完備, 默認觸發是
**, 例如:vim **<TAB>, 或cd **<TAB>, 或ssh **<TAB>, 簡直好用到飛起.
-
# Files under the current directory # - You can select multiple items with TAB key vim **<TAB> # Files under parent directory vim ../**<TAB> # Files under parent directory that match `fzf` vim ../fzf**<TAB> # Files under your home directory vim ~/**<TAB> # Directories under current directory (single-selection) cd **<TAB> # Directories under ~/github that match `fzf` cd ~/github/fzf**<TAB>
-
-
一邊查一邊預覽
-
ps -ef | fzf
seq 100 | fzf
history | fzf
1.3 搜索語法
| Token | Match type | Description |
|---|---|---|
sbtrkt |
fuzzy-match | Items that match sbtrkt |
'wild |
exact-match (quoted) | Items that include wild |
^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 |
-
fzf --preview 'cat {}' -
可以配合管道使用
