In my last article, I introduced the use of the command-line artifact FZF, which can be used not only on the command line, but also in VIm.

The Vim editor is powerful, but it’s a bit weak in terms of project file management and lacks effective file searching, which is far worse than Emacs.

But the FZF plug-in can help vim fill in the gaps.

💡 This article is based on macOS Big Sur 11.0.1, macVim8.2

1. Install

Vim installation will not be described, use Homebrew or directly download the installation package to install.

Before installing FZF, you need to install vim’s plug-in management tool first. The current mainstream management tools are Vundle and VIm-Plug. Here we use the latter.

Installation of the Vim-Plug is simple:

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Copy the code

Once you’re done, you can install the plugin. For this demonstration, just install the plugin for FZF. Create a new.vimrc file in the home directory and fill it with the following:

call plug#begin('~/.vim/plugged')

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

call plug#end()
Copy the code

Install using :PlugInstall. The installation is complete.

2. Use

Before using the FZF plug-in, you need to do a simple configuration. In order to open the file, you need to add the following configuration to the.vimrc:

Call plug#begin('~/.vim/plugged') Plug 'junegunn/ FZF ', {'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' call plug#end()Copy the code

The commands in VIm are slightly different from the command line, with some simple encapsulation of the use of FZF so that you don’t have to do much configuration.

The core command is actually one :Files [path]

Using this command, all files in the target directory (including subdirectories) are displayed in a small window with a preview function.

Select a file using Ctrl-J or Ctrl-k, and press Enter to open the file in the current window. You can open the file using Ctrl-T as a new TAB, Ctrl-X as a horizontal split-screen, or Ctrl-v as a vertical split-screen.

For Files that are already open, you can use :Buffers to view and open the file in the same way as the :Files command.

There is even a degree of integration with Git, using :GFiles to view git files, equivalent to git ls-files. Use: GFiles? Check git status, which is equivalent to git status.

You can also use :Colors to switch themes for VIm.

With these features, VIm is strong in manipulating files, which compensates for one of Vim’s weaknesses.

The above functions are basically enough, FZF’s VIm plug-in also has many advanced uses, interested in you can view the documentation.

The text/Rayjun

                                              

REF

[1] github.com/junegunn/fz…