How to Install Plugins in Vim with Vim-Plug

Vim Plug is a popular plugin manager for Vim, simplifying the process of installing, managing, and updating plugins within Vim.

Plugins in Vim are used to add new features, enhance existing functionality, and customize the editor to suit specific needs and workflows. Vim Plug provides an efficient and straightforward way to handle plugins, making it easier for users to discover, install, and maintain plugins without compromising Vim’s performance or introducing unnecessary complexity.

In this blog post, I will discuss how to install Vim Plug and how to manage plugins using the Vim Plug plugin manager.

Installation of Vim Plug

Installing Vim Plug is a straightforward process. You just need to execute a simple command on your terminal.

macOS and Linux

To install Vim Plug on macOS and Linux, open your terminal and enter the following command:

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

After installing Vim Plug, restart Vim, or enter the following command to apply the changes:

:source $MYVIMRC

Windows

For windows users to install vim-plugin for using vim in powershell, first open powershell and enter the following command

iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | `
    ni $HOME/vimfiles/autoload/plug.vim -Force

After installing Vim Plug, restart Vim, or enter the following command to apply the changes:

:source $MYVIMRC

Verifying the Installation

To verify that Vim Plug has been installed correctly, open Vim and run the command:

:PlugStatus

If Vim Plug is functioning correctly, it will display a list of plugins (which should be empty at this point) in the Vim Plug window.

Adding Plugins using Vim-Plug

Once you have Vim Plug installed, you can start adding plugins to enhance Vim’s functionality.

Updating Your Vim Configuration

To add a plugin using Vim Plug, open your Vim configuration file. The file is typically located at ~/.vimrc. If the file doesn’t exist, Vim will create one for you. Enter the following command to open your Vim configuration file:

vim ~/.vimrc

Add the following line to initialize Vim Plug:

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

"" Install your plugin here

call plug#end()

This line sets the directory where Vim Plug will manage your plugins. By default, plugins will be installed in the ~/.vim/plugged directory.

Here is a sample .vimrc file with some useful settings and plugins that you can copy and paste into your ~/.vimrc configuration:

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                   Plugins area                        "
"                                                       "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""

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

""""""" Vim appearance """""""

Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

""""""" Search """""""

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " File fuzzy search
Plug 'junegunn/fzf.vim'
Plug 'mhinz/vim-grepper' " AMAZING plugin for searching text inside project

call plug#end()

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                   Settings area                       "
"                                                       "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on               " enable syntax highlighting
set background=dark
set termguicolors       " to enable true colors
set t_Co=256            " needed to work in Ubuntu terminal
set nocompatible        " make Vim behave in a more useful way
set mouse=a             " enable mouse in all modes (normal, visual, etc)
set nu                  " line number

Installing Plugins

To install a plugin with Vim Plug, you need to locate the plugin. You can directly install Vim plugins hosted on GitHub repositories using the username and repo name in the following manner:

Plug 'username/plugin-name'

For example, if you want to install the popular airline status line plugin in Vim, you should use the following command within your Vim plugin configuration:

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

"" Install your plugin here
Plug 'vim-airline/vim-airline'

call plug#end()

Then save the file and restart Vim or run the command :source $MYVIMRC within Vim to reload the configuration file. Run the command :PlugInstall within Vim. This command will download and install the specified plugins.

:PlugInstall

Vim Plug will display the progress of the installation in the Vim Plug window. Once the installation is complete, the plugins will be available for use.

Updating Plugins

It is recommended to periodically update your plugins to benefit from new features. Vim Plug provides a feature to sync and update installed plugins. To update a plugin, open your .vimrc file and enter the following command:

:PlugUpdateVim

Plug will fetch updates for each plugin and install them, if available. The progress will be displayed in the Vim Plug window.

Removing Plugins

If you have unused plugins, it’s a good idea to remove them from Vim. This will help Vim load faster. You can remove any plugin you have installed with Vim Plug. To remove a plugin, open your .vimrc file:

vim ~/.vimrc

Then remove the corresponding entry that you used to install the plugin in the first place. After removing the plugin entry, restart Vim or use the :source $MYVIMRC command within Vim to reload the configuration file. Then enter the following command:

:PlugClean

Vim Plug will remove any plugins that are no longer needed, freeing up space and keeping your Vim environment clean.

Listing the Installed Plugins

If you are curious about which plugins are used in your Vim editor, you can quickly check the installed plugins with Vim Plug. To see the list of installed plugins, open Vim and enter the following command:

:PlugStatus

Vim Plug will display the status of each plugin, indicating whether it is installed or not.

Conclusion

In this blog post, we explored the powerful plugin manager Vim Plug and learned how to install, use, and customize plugins in Vim. Vim Plug simplifies the process of extending Vim’s functionality, allowing you to enhance your editing experience and boost productivity.

Share your love

Newsletter Updates

Stay updated with our latest guides and tutorials about Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *