How to Easily Install Vim plugins

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 started his career in IT in the year 2000 as a computer science instructor and worked as a Linux system engineer and senior analyst roles. Currently working in DevOps environments to increase efficiency and improve delivery time in AWS Cloud infrastructure. He is certified in RHEL, CCNA, and MCP and holds a Masters's in computer science. When in his free time love playing cricket, blogging, and listening to music.

SHARE

Comments

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

Leave a Reply

Leave a Comment