Bona:Fide:Cynic

Setting up vim with rake and pathogen.

I have recently started to learn ruby. I like a lot that coders in ruby community use Vim as their editor, in my opinion it is the best editor currently available.
There are many plugins for vim to extend functionality, add syntax indenting and highlighting. I used to install them via bash shell but I am learning ruby and need to practice. I found a very good tool called rake. Now I have a few tasks in my home directory rakefile to do different tasks in various namespaces, like updating websites, backing up server,pc config, etc., but since this post about setting up vim with plugins I’ll share one task with you. As you noticed all plugins are from github. There is an excellent plugin called pathogen created by Tim Pope, thanks a lot man, I like your vim plugins and use them. This plugin allows us to put all plugins in one directory (bundle) and enable them with two lines in .virmrc.

Create rakefile in home directory first:

$vi rakefile

Rake will look for configuration file as far as I remember in this order:
rakefile Rakefile rakefile.rb etc.
So I decided to stick to rakefile as filename because it is the first option in a list. You can copy task into existing rakefile or create one in home dir and paste task in.

#rakefile copyright bonafidecynic
def announce(msg='')
  STDERR.puts msg
end

desc 'Create vim environment and download all plugins'
  task :viminit do
    path_dir = File.expand_path(File.dirname(__FILE__)) + "/.vim/autoload"
    bundle_dir = File.expand_path(File.dirname(__FILE__)) + "/.vim/bundle"
    bundles = [
      "git://github.com/scrooloose/nerdtree.git",
      "git://github.com/tpope/vim-fugitive.git",
      "git://github.com/tpope/vim-git.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/tpope/vim-markdown.git",
      "git://github.com/tpope/vim-liquid.git",
      "git://github.com/tpope/vim-rails.git",
      "git://github.com/timcharper/textile.vim.git",
      "git://github.com/tsaleh/vim-align.git",
      "git://github.com/tsaleh/vim-tcomment.git",
      "git://github.com/tsaleh/vim-supertab.git",
      "git://github.com/msanders/snipmate.vim.git",
      "git://github.com/tpope/vim-haml.git",
    ]

    unless Dir.exists?(".vim")

      announce
      announce "***********************************************************************"
      announce "*       Creating .vim directory and bundles directory                  *"
      announce "***********************************************************************"
      announce

      mkdir_p(path_dir, :mode => 0755)
      mkdir_p(bundle_dir, :mode => 0755)
    end
    cd bundle_dir

    announce
    announce "***********************************************************************"
    announce "*       Trashing everything in .vim/bundle directory!!!               *"
    announce "***********************************************************************"
    announce

    Dir["*"].each {|d| rm_rf d}
    bundles.each do |url|
      dir = url.split('/').last.sub(/\.git$/, '')
      puts "  Unpacking #{url} into #{dir}"
      %x[git clone #{url} #{dir}]
      rm_rf(File.join(dir, ".git"))
    end

    announce
    announce "***********************************************************************"
    announce "*       Installed all vim plugins now going to  install pathogen!     *"
    announce "***********************************************************************"
    announce

    cd path_dir
    url = "git://github.com/tpope/vim-pathogen.git"
    %x[git clone #{url}]
    cp "vim-pathogen/autoload/pathogen.vim", 'pathogen.vim'
    rm_rf "vim-pathogen"

    announce
    announce "***********************************************************************"
    announce "*       Installed all vim plugins and pathogen!                       *"
    announce "*       Don't forget to edit .vimrc if you don't have one,            *"
    announce "*       and include at least these lines as a minimum.                *"
    announce "***********************************************************************"
    announce "*       set nocp \"nocompatible set on                                *"
    announce "*       call pathogen#helptags()                                      *"
    announce "*       call pathogen#runtime_append_all_bundles()                    *"
    announce "*       syntax on \"syntax highlighting on                            *"
    announce "*       filetype on \"enable filetype detection                       *"
    announce "*       filetype indent on \"enable filetype specific indenting       *"
    announce "***********************************************************************"
    announce
end

Obviously you can add other plugins to an array or delete some you don’t like. I might cover plugins in my future posts. This post about installing them not using or configuring. If you don’t have .vimrc copy and paste minimum into it from the message at the end of task, if you have one then copy and paste two pathogen lines to make it work.

To see what tasks are configured in rake:

$rake -T

To execute task created in this post:

$rake viminit

The file tested and works, I am using it, though with a few more plugins, and my .vimrc file more than 150 lines long;-)

blog comments powered by Disqus