VIM automatic prompt code plug-in

1. Introduction to Vim-plug

Vim-plug is a Vim plug-in manager that uses asynchronous parallelism to quickly install, update and uninstall plug-ins. Its installation and configuration are very simple, and it will give a lot of easy-to-read feedback information during the operation. It is a free, open source, very fast, parallel installation or update of plug-ins, and a minimalist vim plug-in manager.

Vim-plug acquisition link: GitHub – junegunn/vim-plug: :hibiscus: Minimalist Vim Plugin Manager

Vim Awesomeicon-default.png?t=N7T8https://vimawesome.com/

2. Directory preparation

Check if there is a ~/.vim folder under the user

mkdir ~/.vim
cd ~/.vim
mkdir plugged plugin syntax colors doc autoload

Introduction to the directories under the ~/.vim folder

~/.vim/autoload/ It is a very important directory, although it sounds more complicated than it is. In short, it places files that are automatically loaded and run when you really need them, rather than when vim starts.
~/.vim/colors/ is used to store vim color schemes.
~/.vim/plugin/ stores plug-ins that will be run every time vim is started. That is to say, any plug-in you want to run when vim starts is placed in this directory. We can put the plug-in .vim downloaded from vim-plug official website
~/.vim/syntax/Syntax description script. We put plugins related to text (such as C language) grammar
~/.vim/doc/ is where the documentation for the plug-in is placed. For example: can be used when asking for help.
Files in ~/.vim/ftdetect/ will also be run when vim starts. Sometimes this directory may not exist. ftdetect stands for "filetype detection (file type detection)". Files in this directory should use autocommands to detect and set the file type, and nothing else. That is, they should only have one or two lines.
~/.vim/ftplugin/The files in this directory are a little different. When vim sets a value for the filetype of the buffer, vim will search for a file with the same name as filetype in the ~/.vim/ftplugin/ directory. For example, after you run the command set filetype=derp, vim will search for the file ~/.vim/ftplugin/derp.vim and run it if it exists. Not only that, it will also run all files in the subdirectory with the same name under ftplugin, such as ~/.vim/ftplugin/derp/. All files in this folder will be run. Each time it is enabled, the local buffering option should be set for different file types. If set to the global buffering option, all open buffers will be overwritten.
The files in ~/.vim/indent/ are very similar to those in ftplugin, they are also loaded based on their names. It places the indentation of the relevant file type. For example, how should python be indented, how should java be indented, etc. In fact, it can also be placed in ftplugin, but it is listed separately just to facilitate file management and understanding.
~/.vim/compiler/ is very similar to indent. It contains options for how the corresponding file type should be compiled.
The files in ~/.vim/after/ will also be loaded every time vim starts, but it will wait until ~/.vim/plugin/ is loaded before loading the content in after, so it is called after.
~/.vim/spell/spell check script.

3. Installation of Vim-plug

3.1 Offline Installation

After downloading and decompressing the plug.vim file, place it in the following ~/.vim/autoload directory depending on the operating system:

cp plug.vim ~/.vim/autoload/plug.vim

3.2 online installation (frequently fails)

$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

4. Adding and deleting plug-ins

vim-plug supports plug-ins whose source code is hosted on GitHub. You can find the mirrors of all plug-ins in the vim official website (https://www.vim.org) on “vim-scripts (Scrappy Scraper) · GitHub”. You can also install the Windows version of Git to view the vim plug-in.

To install plugins, you must first declare them in the Vim configuration file as shown below.

Generally, the configuration file of Vim is ~/.vimrc, and the configuration file of Neovim is ~/.config/nvim/init.vim.

Remember, when you declare a plug-in in the configuration file, the list should start with call plug#begin(PLUGIN_DIRECTORY) and end with plug#end().

Edit the contents of the ~/.vimrc file, such as installing the “lightline.vim” plug-in

call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
call plug#end()

Run the command to reload:

source ~/.vimrc

5. Usage of vim-plug command in vim

5.1 Install plug-in

If you want to install a new plug-in, first find its URL at http://github.com, then append it between call plug#begin() and call plug#end() in the vimrc configuration file, and finally execute the following command Install all referenced plugins:

:PlugInstall

You can also use the following command to specify the installation of specific plug-ins:

:PlugInstall gist-vim

5.2 Uninstall plug-in

If you want to uninstall a plug-in, please comment or delete the corresponding plug-in configuration information in the vimrc configuration file, and then execute the following command:

:PlugClean

5.3 update plug-in

The vim-plug plugin itself can be updated using the following command:

:PlugUpgrade

All installed plugins can be updated in bulk using the following command:

:PlugUpdate

5.4 Plug-in Status

Use the following command to view the status information of currently installed plug-ins:

:PlugStatus

Six, install the code completion plug-in coc.nvim

coc.nvim depends on nodejs, so you need to install nodejs first

curl -sL install-node.now.sh/lts | bash

Add configuration in ~/.vimrc file

Plug 'neoclide/coc.nvim', {'branch': 'release'}

After writing, the content in .vimrc is as follows

call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

Then install using PlugInstall

$ vim #Open vim
:PlugStatus #In the bottom command line mode, check the plug-in status
:PlugInstall #Install the plug-in previously declared in the configuration file

After installation, enter :CocInfo in the vim command line to view version information

6.2 configuration

Install dependencies first. coc mainly relies on clangd for automatic code completion, so clangd needs to be installed in advance.

sudo apt install clangd -y

coc.nvim is just a platform that allows you to install various language plug-ins to achieve completion effects in different languages. Therefore, we can only achieve completion if we install the corresponding language plug-in. Take C/C++ as an example:

Configure the coc.nvim configuration file coc-settings.json by entering :CocConfig in the command mode in vim

{
"languageserver": {
    "clangd": {
      "command": "clangd",
      "rootPatterns": ["compile_flags.txt", "compile_commands.json"],
      "filetypes": ["c", "cc", "cpp", "c + + ", "objc", "objcpp"]
    }
  }
}

Seven uses

At that time, when using vim to edit a c/c++ text, the prompt would be automatically turned on.

Press ctrl+n to select down

ctrl + p select up

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. CS entry skill treeLinux introductionFirst introduction to Linux37703 people are learning the system