Manage Vim Plugins With Pathogen

Introduction

There’s no denying that Vim is awesome on its own. It provides users with unprecedented configuration potential and quick, powerful commands. That said, Vim can get even better with the use of plugins.

There are hundreds of plugins that can seriously amp-up your Vim installation. Many of them are tailored for specific uses, like programming in a certain language or even writing. Others are more general and enhance Vim’s existing capabilities. Whichever it is that you need, you’re going to have to manage those packages.

There are a number of Vim package managers, but Pathogen is the most universal and simple to use and install. Pathogen works by pulling all of the Vim plugins in a certain directory into your Vim installation and activating them with a single line in your .vimrc file.

Required Packages

Before you get started, you should probably make sure that you have both Vim and Git installed on your system. These are both very common packages, so there’s not too much need to go into detail here, just install them, if you haven’t already.

Debian/Ubuntu

# apt-get install vim git

Fedora/CentOS

# dnf/yum -y install vim git

Arch

# pacman -S vim git

Setting Up The Directories

All of this is done locally, on a per-user basis. It requires a .vim folder in your /home directory. If you don’t already have it, create it.

$ mkdir ~/.vim

Inside that folder, you must create two more. cd in and make autoload and bundle.

$ cd ~/.vim
$ mkdir autoload
$ mkdir bundle

Installing Pathogen

Pathogen is best installed via Git. It’s actually a Vim plugin itself, so it’s a Vim script that needs to be cloned from its Git repository. Since you want Pathogen to run automatically, it needs to be installed into the autoload directory that you just created.

$ cd autoload
git clone https://github.com/tpope/vim-pathogen.git

When that clone finishes, you will have Pathogen installed.

Configuring .vimrc

You do have to add one line to your .vimrc file to use Pathogen. If you somehow don’t already have the file, you can create it at the same time you add Pathogen. The file exists at the root of your /home directory.

vim ~/.vimrc

If you did just create the file for the first time, and you don’t have anything else, add these few lines.

set nocompatible
filetype plugin indent on
syntax on

execute pathogen#infect()

If you have an existing .vimrc that you built up, the following line to the file.

execute pathogen#infect()

Either way, you should make sure that you have at least the lines above in your configuration. All you need to do for the changes to take effect is close out of Vim and open it again.

Installing and Managing Plugins

The whole reason you installed Pathogen was to get those great plugins to boost Vim’s capabilities. Now, you’re finally ready to pick a few and install them.

Vim-airline is a very popular status line plugin for monitoring what’s going on in Vim while you’re using it. This guide will go over installing it. If you really don’t want airline, just pick another plugin. The procedure is the same.

Installing

Before installing any plugin on Vim, you have to find it first. Most of them are available through Github, and you can just do a quick search for them. To save time, you can get airline here.

Click on the “Clone or Download” button and copy the Git address. If you want to know more about vim-airline, that Github page is an excellent resource.

With the git link copied, cd into the bundle directory that you created and clone the Git repository.

$ cd ~/.vim/bundle
$ git clone https://github.com/vim-airline/vim-airline

Pathogen will pull in vim-airline every time it starts. To see the airline bar when you start up vim, add the lines belo to your .vimrc file.

set laststatus=2

There’s a ton more that you can do with vim-airline, but that’s outside the scope of this guide. Refer to the Github page for more, or just experiment.

Updates

Updates can be accomplished by performing a pull with Git inside the plugin directory. For example, to update vim-airline, you would cd into the vim-airline directory inside bundle and pull.

$ cd ~/.vim/bundle/vim-airline
$ git pull origin master

The same will be true of very plugin that you cloned with Git. You can easily write up a shell script to iterate through each directory and pull and even set it to a cron job to fully automate the update process, if you want to.

Keep in mind that you can keep Pathogen itself up-to-date the same way because you cloned it from Github too.

Closing Thoughts

That’s about all there is to say. Pathogen is dead simple. It allows you to keep your plugins installed and up-to-date with very little effort or overhead, since it’s not a full package manager. It also wont run into troublesome dependency issues or conflicts, and it won’t pull in anything you don’t want or need. Welcome to the world of Vim plugins!



Comments and Discussions
Linux Forum