The Modern Vim Config with Pathogen

Unix gets a whole lot right, but the way it dumps everything into the same filesystem isn't one of them. Traditionally, every application you install will put files under /etc, /usr/bin, /var, /lib, and so on. This makes it impossible to confidently extract an installed application, and lead to the development of various package management tools.

Vim's legacy

Unfortunately, Vim inherited that original philosophy. Terribly misguided attempts have been made in the past to create a package management system for Vim plugins. The Vimball format is particularly painful - non-standard file format, unusable from the commandline, and all files dropped under ~/.vim willy-nilly.

Pathogen

Thankfully, our hero Tim Pope has penned pathogen.vim - a sane package manager for Vim plugins. With pathogen, all of your plugins are stored in separate directories under ~/.vim/bundle:

~/.vim $ ls bundle 

IndexedSearch     vim-align         vim-rails         vim-surround
gist              vim-cucumber      vim-repeat        vim-tcomment
jquery            vim-fugitive      vim-ruby          vim-vividchalk
nerdtree          vim-git           vim-ruby-debugger
snipmate.vim      vim-haml          vim-shoulda
textile.vim       vim-markdown      vim-supertab

This means removing a plugin is as simple as deleting that directory. Just the way it should be.

Installation

To get started, I recommend moving your ~/.vim directory out of the way and starting fresh. Then make the ~/.vim/autoload directory and download the pathogen.vim file there.

~/.vim master $ ls autoload
pathogen.vim

Now call pathogen from your .vimrc like such:

call pathogen#infect()
call pathogen#helptags()

…and that's it! This is the only plugin you'll install directly into your ~/.vim directory. After that, any plugin you install into the ~/.vim/bundle directory will be seen by vim. At this point, you can start copying in the contents of your .vimrc and .gvimrc files, taking the time to clean them up as you go.

Automation

To make management of the bundle directory a little easier, I penned up a quick ruby script, which I saved as ~/.vim/update_bundles. Running this script will remove all plugins you've installed manually, and will update them to the latest versions.

#!/usr/bin/env ruby

git_bundles = [ 
  "git://github.com/astashov/vim-ruby-debugger.git",
  "git://github.com/ervandew/supertab.git",
  "git://github.com/godlygeek/tabular.git",
  "git://github.com/hallison/vim-rdoc.git",
  "git://github.com/msanders/snipmate.vim.git",
  "git://github.com/pangloss/vim-javascript.git",
  "git://github.com/scrooloose/nerdtree.git",
  "git://github.com/timcharper/textile.vim.git",
  "git://github.com/tpope/vim-cucumber.git",
  "git://github.com/tpope/vim-fugitive.git",
  "git://github.com/tpope/vim-git.git",
  "git://github.com/tpope/vim-haml.git",
  "git://github.com/tpope/vim-markdown.git",
  "git://github.com/tpope/vim-rails.git",
  "git://github.com/tpope/vim-repeat.git",
  "git://github.com/tpope/vim-surround.git",
  "git://github.com/tpope/vim-vividchalk.git",
  "git://github.com/tsaleh/taskpaper.vim.git",
  "git://github.com/tsaleh/vim-matchit.git",
  "git://github.com/tsaleh/vim-shoulda.git",
  "git://github.com/tsaleh/vim-tcomment.git",
  "git://github.com/tsaleh/vim-tmux.git",
  "git://github.com/vim-ruby/vim-ruby.git",
  "git://github.com/vim-scripts/Gist.vim.git",
]

vim_org_scripts = [
  ["IndexedSearch", "7062",  "plugin"],
  ["jquery",        "12107", "syntax"],
]

require 'fileutils'
require 'open-uri'

bundles_dir = File.join(File.dirname(__FILE__), "bundle")

FileUtils.cd(bundles_dir)

puts "trashing everything (lookout!)"
Dir["*"].each {|d| FileUtils.rm_rf d }

git_bundles.each do |url|
  dir = url.split('/').last.sub(/\.git$/, '')
  puts "unpacking #{url} into #{dir}"
  `git clone #{url} #{dir}`
  FileUtils.rm_rf(File.join(dir, ".git"))
end

vim_org_scripts.each do |name, script_id, script_type|
  puts "downloading #{name}"
  local_file = File.join(name, script_type, "#{name}.vim")
  FileUtils.mkdir_p(File.dirname(local_file))
  File.open(local_file, "w") do |file|
    file << open("http://www.vim.org/scripts/download_script.php?src_id=#{script_id}").read
  end
end

This script (and more) is avilable in my dotfiles repo.