模糊搜索神器fzf;
fzf是一个交互式的搜索工具,他从标准输入读取一个候选列表,并将选择项写入标准输出。
你在任何地方用到搜索或者从多个候选项中选择一个时,都应该想到fzf,用fzf增强原来的搜索选择,让你爽的飞起!
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf ~/.fzf/install
交互式搜索文件
find * -type f | fzf > selected
搜索文件并使用vim打开
vim $(fzf)
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 |
快捷键 | 描述 |
ctrl+t | 搜索当前目录下的文件或者目录并打印到命令行中 |
ctrl+r | 将原来的历史命令搜索增强 |
alt+c | 选择目录并切换到选择的目录 |
# 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>
还有我不常用的,进程号搜索,环境变量设置,host搜索
然后在.zshrc里用函数或别名
alias tt='fzf --preview '"'"'[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (bat --style=numbers --color=always {} || rougify {} || highlight -O ansi -l {} || coderay {} || cat {}) 2> /dev/null | head -500'"'"
切换git分支
alias gcof='git checkout ${$(git branch --remote | fzf)#"origin/"}'
merge指定分支内容
alias gmf='git merge ${$(git branch --remote | fzf)#"origin/"}'
官方git:https://github.com/junegunn/fzf
https://segmentfault.com/a/1190000011328080
https://www.jianshu.com/p/b48131e4ad06