fzf(Fuzzy File Finder) enhances the efficiency and convenience of your command-line workflow.

Installation of fzf

1
2
3
4
5
6
# Install the fzf itself by Homebrew
brew install fzf

# Install the auto-completion and the key bindings
# Add the .fzf.zsh which contains the configuration of these downloaded files to the .bashrc and the .zshrc
$(brew --prefix)/opt/fzf/install

image.png

  • The .fzf.zsh file default contents are these below:
  • key-bindings.zsh only contains CTRL-R, CTRL-T, and ALT-C
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # Setup fzf
    # ---------
    if [[ ! "$PATH" == */opt/homebrew/opt/fzf/bin* ]]; then
    PATH="${PATH:+${PATH}:}/opt/homebrew/opt/fzf/bin"
    fi

    # Auto-completion
    # ---------------
    [[ $- == *i* ]] && source "/opt/homebrew/opt/fzf/shell/completion.zsh" 2> /dev/null

    # Key bindings
    # ------------
    source "/opt/homebrew/opt/fzf/shell/key-bindings.zsh"

Link with NeoVIM

Installation(init.vim)

  • If there is no fzf binary files have been installed before, We should install fzf separately in NeoVim(By Vim-Plug or something else).
    Otherwise, we could only specify the fzf pathname in our local drive which is enough.
    1
    2
    3
    4
    5
    6
    7
    " If there is no fzf binary files before
    Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
    Plug 'junegunn/fzf.vim'

    " If fzf has been installed at the local drive
    Plug '/opt/homebrew/opt/fzf'
    Plug 'junegunn/fzf.vim'

Configuration(init.vim)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let $FZF_DEFAULT_OPTS="--height 40% --border --preview 'bat --style=numbers --color=always --line-range :500 {}'"

command! -bang -nargs=? -complete=dir Files call fzf#vim#files('~/', <bang>0)
nnoremap <C-f> :Files<CR>

command! -bang -nargs=* MRU call fzf#vim#history(fzf#vim#with_preview())
noremap <C-h> :MRU<CR>

command! -bang -nargs=* Ag
\ call fzf#vim#ag(
\ '',
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%', '?'),
\ <bang>0)
noremap <C-c> :Ag<CR>

There are defined 3 keybindings(CTRL-f, CTRL-h, CTRL-c), and Ag was used software installed in our local drive called The silver searcher (GitHub - ggreer/the_silver_searcher: A code-searching tool similar to ack, but faster.)

fzf(Fuzzy File Finder) enhances the efficiency and convenience of your command-line workflow.

https://resek4.github.io/2022/12/31/fzf/

Author

Resek4

Posted on

2022-12-31

Updated on

2023-03-22

Licensed under

Comments