Configuration and use of search artifact fzf under Linux

Jiangdong flower master Minming 2022-09-23 08:51:39 阅读数:607

configurationusesearchartifactfzf

fzf is widely used, especially in the use of vim, here is just an introduction to the use of simple configuration in the linux command line:

I. Installation

The installation here is the source code installation. In addition, you can also use the command to install apt install fzf. The source code installation command is as follows:

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf~/.fzf/install

It is worth noting that even if you use the source code to install, you need to connect to the network and download the dependency package

[email protected]:~/test/fzf$ ./installDownloading bin/fzf...- Found in $PATH- Creating symlink: bin/fzf -> /usr/bin/fzf- Checking fzf executable ... 0.17.5 != 0.33.0% Total % Received % Xferd Average Speed ​​Time Time Time CurrentDload Upload Total Spent Left Speed0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: github.comgzip: stdin: unexpected end of filetar: Child returned status 1tar: Error is not recoverable: exiting now--2022-09-12 18:42:33-- https://github.com/junegunn/fzf/releases/download/0.33.0/fzf-0.33.0-linux_amd64.tar.gzResolving host github.com (github.com)... Failed: Domain name resolution temporarily failed.wget: Unable to resolve host address "github.com"gzip: stdin: unexpected end of filetar: Child returned status 1tar: Error is not recoverable: exiting now- Failed to download with curl and wget!!!go executable not found. Installation failed.

Upgrade:

cd ~/.fzf && git pull && ./install

2. Layout

There are many configuration methods and methods on the Internet, but for me, I only need to preview the file content during the process of searching for files, and it does not need to occupy too much interface.During the configuration process, the layout has only two simple functions: the size setting of the preview window and the file search preview window.

fzf default full screen mode, you can customize the height

vim $(fzf --height 40%)

You can set default values ​​by $FZF_DEFAULT_OPTS

export FZF_DEFAULT_OPTS='--height 40% --reverse --border'

Three, preview window

If the --preview option is used, fzf will automatically open the file of the current entry with an external program, and {} will be replaced by the content of the line selected by fzf

fzf --preview 'cat {}'

It is recommended to install rougify (install ruby ​​first, then gem install rouge)
Then use functions or aliases in .zshrc, if you use bash, then modifyThe file is .bashrc

fzfp() {fzf --preview '[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (rougify {} || highlight -O ansi -l {} || coderay {}|| cat {}) 2> /dev/null | head -500'alias tt='fzf --preview '"'"'[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (rougify {} || highlight -O ansi -l {} || coderay {} || cat {}) 2> /dev/null | head -500'"'"}

Four. Effects

1. Enter fzf

insert image description here

2. Enter fzfp
insert image description here
Five, offline download

If the environment is offline, you may need to download and install fzf offline. The installation tutorial is as follows:

https://blog.csdn.net/weixin_43958105/article/details/119531279p>

copyright:author[Jiangdong flower master Minming],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/266/202209230842521256.html