# How to Install Plugins in Neovim


We are going to use a plugin manager **'vim-plug'**
for installing & managing plugins in neovim.

The following tutorial is for **Neovim** & not for **Vim**.

![installer.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1668926546714/48Y3W4lF5.gif align="left")

## Create Config

Create a directory for Neovim config if not already

```
mkdir ~/.config/nvim
```

Create an `init.vim` file

```
touch ~/.config/nvim/init.vim
```

## Vim-plug installation

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

## Create a file for plugins

Create a new file `plugins.vim` for organisation.

```
mkdir ~/.config/nvim/vim-plug

touch ~/.config/nvim/vim-plug/plugins.vim
```

## Adding plugins

Add the following to `~/.config/nvim/vim-plug/plugins.vim`

``` vim
" auto-install vim-plug
if empty(glob('~/.config/nvim/autoload/plug.vim'))
  silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  "autocmd VimEnter * PlugInstall
  "autocmd VimEnter * PlugInstall | source $MYVIMRC
endif

call plug#begin('~/.config/nvim/autoload/plugged')

    " Better Syntax Support
    Plug 'sheerun/vim-polyglot'
    " File Explorer
    Plug 'scrooloose/NERDTree'
    " Auto pairs for '(' '[' '{'
    Plug 'jiangmiao/auto-pairs'

call plug#end()
```

We are adding 3 plugins they are optional but copy the rest of the snippet.

To add a new plugin add between `call plug#begin()` & `call plug#end()` in the following Syntax

``` vim
	" Comment for the plugin
	Plug 'author/plugin-name'
```

## Source plugins.vim

To source plugins.vim to init.vim 
add the following to `init.vim`

```
source $HOME/.config/nvim/vim-plug/plugins.vim
```

## Vim-plug commands

Open `nvim`

```
nvim
```

### Plugin Status

Check the status of your plugins

```
:PlugStatus
```

### Installing Plugins

Install all plugins

```
:PlugInstall
```

### Updating Plugins

To update your plugins

```
:PlugUpdate
```

### Removing Plugins

To remove plugins 
1. Remove the plugin from plugins.Vim
1. Use the following commands

```
:PlugClean
```

## References

- [vim-plug GitHub README](https://github.com/junegunn/vim-plug)
- [Neovim - Installing Plugins with Vim-Plug](https://youtu.be/QB9V__3VO2s)

