How to manage Vim plugins

Last updated on August 26, 2020 by Adrien Brochard

Vim is a versatile, lightweight text editor on Linux. While its initial learning curve can be overwhelming for an average Linux user, its benefits are completely worthy. As far as the functionality goes, Vim is fully customizable by means of plugins. Due to its high level of configuration, though, you need to spend some time with its plugin system to be able to personalize Vim in an effective way. Luckily, we have several tools that make our life with Vim plugins easier. The one I use on a daily basis is Vundle.

What is Vundle?

Vundle, which stands for Vim Bundle, is a Vim plugin manager. Vundle allows you to install, update, search and clean up Vim plugins very easily. It can also manage your runtime and help with tags. In this tutorial, I am going to show how to install and use Vundle.

Installing Vundle on Linux

First, install Git if you don't have it on your Linux system.

Next, create a directory where Vim plugins will be downloaded and installed. By default, this directory is located at ~/.vim/bundle

$ mkdir -p ~/.vim/bundle

Now go ahead and install Vundle as follows. Note that Vundle itself is another Vim plugin. Thus we install Vundle under ~/.vim/bundle we created earlier.

$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Configuring Vundle

Now set up you .vimrc file as follows:

set nocompatible              " This is required
filetype off                  " This is required

" Here you set up the runtime path
set rtp+=~/.vim/bundle/Vundle.vim

" Initialize vundle
call vundle#begin()

" This should always be the first
Plugin 'gmarik/Vundle.vim'

" This examples are from https://github.com/gmarik/Vundle.vim README
Plugin 'tpope/vim-fugitive'

" Plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'

"Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'

"git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'

" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" Avoid a name conflict with L9
Plugin 'user/L9', {'name': 'newL9'}

"Every Plugin should be before this line

call vundle#end()            " required

Let me explain the above configuration a bit. By default, Vundle downloads and installs Vim plugins from github.com. You can modify the default behavior.

To install from Github:

Plugin 'user/plugin'

To install from another Git repo:

Plugin 'git://git.another_repo.com/plugin'

To install from a local file:

Plugin 'file:///home/user/path/to/plugin'

Also you can customize others such as the runtime path of you plugins, which is really useful if you are programming a plugin yourself, or just want to load it from another directory that is not ~/.vim.

Plugin 'rstacruz/sparkup', {'rtp': 'another_vim_path/'}

If you have plugins with the same names, you can rename you plugin so that it doesn't conflict.

Plugin 'user/plugin', {'name': 'newPlugin'}

Using Vundle Commands

Once you have set up you plugins with Vundle, you can use it to to install, update, search and clean unused plugins using several Vundle commands.

Installing a new plugin

The PluginInstall command will install all plugins listed in your .vimrc file. You can also install just one specific plugin by passing its name.

:PluginInstall
:PluginInstall <plugin-name>

Cleaning up an unused plugin

If you have any unused plugin, you can remove it by using the PluginClean command.

:PluginClean

Searching for a plugin

If you want to install a plugin from a plugin list provided, search functionality can be useful.

:PluginSearch <text-list>

While searching, you can install, clean, research or reload the same list on the interactive split. Installing plugins won't load your plugins automatically. To do so, add them to you .vimrc file.

Conclusion

Vim is an amazing tool. It can not only be a great default text editor that can make your work flow faster and smoother, but also be turned into an IDE for almost any programming language available. Vundle can be a big help in personalizing the powerful Vim environment quickly and easily.

Note that there are several sites that allow you to find the right Vim plugins for you. Always check https://www.vim.org/scripts/, Github or http://www.vimawesome.com for new scripts or plugins. Also remember to use the help provider for you plugin.

Keep rocking with your favorite text editor!

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean