How to Easily Install Vim plugins

Written by: Bobbin Zachariah   |   Last updated: June 17, 2022

Most Linux distribution is now preinstalled with VIM 8+ version. Vim 8 has built support for packages. You can now easily install Vim plugins with this added support.

Package support helps to add, update, remove and manage packages. Vim can natively load third-party packages without the help of any plugin manager.

In this tutorial, you learn how to install Vim plugins manually and using a plugin manager.

Install Vim plugins

Let's check how to install Vim plugins manually, this is recommended method for Vim 8+

By default, Vim expects each plugin to be stored in the ~/.vim/pack/<my-plugins>/. When Vim starts, it will load all plugins stored in /.vim/pack/my-plugins/start. You can give any name for the directory my-plugins.

Create the directory to store Vim plugins:

$ mkdir -p ~/.vim/pack/my-plugins/start

If you don't want the Vim plugin to start automatically at the start, create a subfolder opt under the plugin directory ( here 'my-plugins') and add package there.

The package added in opt can be loaded to memory by:

:packadd packagename

For example, let's install two Vim plugins - NERDTree and Vim Airline.

$ mkdir -p ~/.vim/pack/my-plugins/start/NERDTree/
$ git clone --depth 1 https://github.com/preservim/nerdtree.git ~/.vim/pack/my-plugins/start/NERDTree/

$ mkdir -p ~/.vim/pack/my-plugins/start/Airline/
$ git clone --depth 1 https://github.com/vim-airline/vim-airline.git ~/.vim/pack/my-plugins/start/Airline/

Install Vim plugin using a plugin manager

Plugin Managers is still useful because of its features. Plugin manager has features such as updating, disabling plugins make it easy to manage vim plugins.

Popular plugin managers are Vim-plug, Vundle, Pathogen, dein.vim, and VAM.

Let's check how to install vim plugins using vim-plug.

Step 1: Install the vim-plug

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

Step 2: Create ~/.vimrc file

$ touch ~/.vimrc file

Step 3: Add plugins to install in ~/.vimrc file

Add the name and location of each plugin to be installed between the plug#begin and plug#end() lines.

call plug#begin()
Plug 'preservim/NERDTree'
Plug 'vim-airline/vim-airline'
Plug 'https://github.com/ap/vim-css-color'
call plug#end()

Step 4: Install Plugins

Open Vim on your terminal and type:

:PlugInstall
install vim-plug using the plugin manager

To update a single plugin, type:

:PlugUpdate vim-airline 

Conclusion

In this tutorial, we learned how to install Vim Plugins manually and using a plugin manager.

If you have any feedback and suggestion please comment below.

About The Author

Bobbin Zachariah

Bobbin Zachariah

Bobbin Zachariah is an experienced Linux engineer who has been supporting infrastructure for many companies. He specializes in Shell scripting, AWS Cloud, JavaScript, and Nodejs. He has qualified Master’s degree in computer science. He holds Red Hat Certified Engineer (RHCE) certification and RedHat Enable Sysadmin.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment