Pathogenから、Vundleへ、vim-pluginの管理を移行。


追記:2011/11/01:VundleからNeoBundleに移行しました。
http://d.hatena.ne.jp/sugilog/20111101/1320158226


以前Pathogenの導入をしてからそれほどたってないけど、もはやvimのplugin管理はVundleが主流になりつつあるみたい(主観)

ということで、vim-users.jpのエントリーを参考にしてVundleを導入。
http://vim-users.jp/2011/04/hack215/
ついでに、Pathogenからの切り替えの簡単さをご紹介できればなんて。

前準備

Pathogen関連の設定のoff

とりあえず変な競合があると嫌なので、Pathogenをoff。

.vimrcにあるPathogenの以下の設定を消します。

~/.vimrc

call pathogen#runtime_append_all_bundles()

でもって、pathogenで管理していた.vim/自体を、読み込まれないようにしておきます。
(作業が終わるまでの間、tmp/にbackupしておくことに。)

% mv ~/.vim ~/tmp/
vimの既存設定をいくつかoff

Vundleを導入するためには、以下の設定がVundleの設定よりも先にあるとダメらしいので、消してしまいます。
必要な人は、後で追加。

~/.vimrc

filetype on
filetype indent on
filetype plugin on

導入

Vundleの導入

自分は、設定ファイル系をdotfilesというディレクトリで管理しているので、そのディレクトリにVundleをいれます
ついでに、そのdotfiles自体は、git(github)管理にしているので、Vundleはsubmoduleとして組み込みます。

% cd ~/dotfiles
% git submodule add http://github.com/gmarik/vundle.git ~/dotfiles/.vim/vundle.git
vimrcへの設定

Vundleを動かしてあげるための設定を、vimrcに追加します。
pluginを読み込まないようにしてしまっているので、vim起動時に若干エラーしますが、気にしないw
まずは、プラグイン管理以外の設定を書いてしまいます。

~/.vimrc

set nocompatible
filetype off
set rtp+=~/dotfiles/.vim/vundle.git/
call vundle#rc()

" pluginの管理設定をここに書く予定

filetype plugin indent on

vim-users.jpにあるように、あらかじめfiletype offにしておいて、プラグインの管理設定のあとに、必要なfiletypeをonにします。

Vundleの本体は、set rtp...で明示しているので、~/.vimである必要がないです
つまり、自分の場合、dotfilesから、symbolic linkを作るとか、そういう煩わしいことが必要なくなる、っていうのが一つのポイント。
dotfilesに汎用的な設定を集約できるので管理性が向上します。

pluginの管理設定の追加

Pathogenでは、~/.vim/bundle直下に、あらかじめ自分自身でプラグインを設置する必要がありました。
Vundleでは、プラグインは必要なモノを.vimrcに明示しておけば良いわけです。
以下のような感じ

Bundle 'PluginName or PluginUrl'

前準備の段階で、Pathogenのときの~/.vimディレクトリをtmpディレクトリに移動させておきました。
Pathogenのときに、プラグインをgit submoduleとして管理していた場合、.vim/.gitmodulesファイルにsubmoduleの設定があります。
自分の場合は以下のような形。

.vim/.gitmodules

[submodule "bundle/vim-pathogen"]
  path = bundle/vim-pathogen
  url = git://github.com/tpope/vim-pathogen.git
[submodule "bundle/neocomplcache.git"]
  path = bundle/neocomplcache.git
  url = git://github.com/Shougo/neocomplcache.git
[submodule "bundle/EnhancedCommentify.git"]
  path = bundle/EnhancedCommentify.git
  url = git://github.com/hrp/EnhancedCommentify.git
[submodule "bundle/yanktmp.git"]
  path = bundle/yanktmp.git
  url = git://github.com/vim-scripts/yanktmp.vim.git
[submodule "bundle/matchit.git"]
  path = bundle/matchit.git
  url = git://github.com/tsaleh/vim-matchit.git
[submodule "bundle/rails.git"]
  path = bundle/rails.git
  url = git://github.com/tpope/vim-rails.git
[submodule "bundle/SvnDiff.git"]
  path = bundle/SvnDiff.git
  url = git://github.com/vim-scripts/svn-diff.vim.git
[submodule "bundle/align.git"]
  path = bundle/align.git
  url = git://github.com/tsaleh/vim-align.git
[submodule "bundle/rubytest.git"]
  path = bundle/rubytest.git
  url = git://github.com/janx/vim-rubytest.git
[submodule "bundle/unite.git"]
  path = bundle/unite.git
  url = git://github.com/Shougo/unite.vim.git

Vundleの設定をつくるために、これを、.vimrcにコピペします。
そして、Vundleが解釈できるように修正します。

  1. [submodule...の行と、path =...の行はいらないので、削除します。
    • ついでにPathogenはいらなくなるので、Pathogenに関係する行も削除します。
    • そうすると
  url = git://github.com/Shougo/neocomplcache.git
  url = git://github.com/hrp/EnhancedCommentify.git
  url = git://github.com/vim-scripts/yanktmp.vim.git
  url = git://github.com/tsaleh/vim-matchit.git
  url = git://github.com/tpope/vim-rails.git
  url = git://github.com/vim-scripts/svn-diff.vim.git
  url = git://github.com/tsaleh/vim-align.git
  url = git://github.com/janx/vim-rubytest.git
  url = git://github.com/Shougo/unite.vim.git
  1. 上の状態になったら、うまく置換してあげれば、Vundleが解釈できる状態になります。
:'<,'>s/.*github.com\//Bundle '/gi
:'<,'>s/\.git/'/gi

そうすると、以下の状態になります。

set nocompatible
filetype off
set rtp+=~/dotfiles/.vim/vundle.git/
call vundle#rc()

Bundle 'Shougo/neocomplcache'
Bundle 'hrp/EnhancedCommentify'
Bundle 'vim-scripts/yanktmp.vim'
Bundle 'tsaleh/vim-matchit'
Bundle 'tpope/vim-rails'
Bundle 'vim-scripts/svn-diff.vim'
Bundle 'tsaleh/vim-align'
Bundle 'janx/vim-rubytest'
Bundle 'Shougo/unite.vim'

filetype plugin indent on
Pluginのインストール

といってもgit経由でマシンにコピーされるという感じですが。
以下のvimのコマンドで実行。

:BundleInstall

※ちなみに、~/.vimにインストールされるのですが、~/.vimがなければ勝手に作ってくれます。

そうするとあとは勝手にやってくれます。

Cloning into /Users/takayukisugita/.vim/bundle/neocomplcache...
remote: Counting objects: 7190, done.
remote: Compressing objects: 100% (3079/3079), done.
remote: Total 7190 (delta 4046), reused 6919 (delta 3781)
Receiving objects: 100% (7190/7190), 1.25 MiB | 436 KiB/s, done.
Resolving deltas: 100% (4046/4046), done.
Cloning into /Users/takayukisugita/.vim/bundle/EnhancedCommentify...
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 10 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
Cloning into /Users/takayukisugita/.vim/bundle/yanktmp.vim...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 6 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
Cloning into /Users/takayukisugita/.vim/bundle/vim-matchit...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 12 (delta 0), reused 12 (delta 0)
Unpacking objects: 100% (12/12), done.
Cloning into /Users/takayukisugita/.vim/bundle/vim-rails...
remote: Counting objects: 3030, done.
remote: Compressing objects: 100% (894/894), done.
remote: Total 3030 (delta 1379), reused 2958 (delta 1312)
Receiving objects: 100% (3030/3030), 705.38 KiB | 247 KiB/s, done.
Resolving deltas: 100% (1379/1379), done.
Cloning into /Users/takayukisugita/.vim/bundle/svn-diff.vim...
remote: Counting objects: 26, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 26 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (26/26), done.
Cloning into /Users/takayukisugita/.vim/bundle/vim-align...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 12 (delta 0), reused 12 (delta 0)
Unpacking objects: 100% (12/12), done.
Cloning into /Users/takayukisugita/.vim/bundle/vim-rubytest...
remote: Counting objects: 144, done.
remote: Compressing objects: 100% (78/78), done.
remote: Total 144 (delta 40), reused 138 (delta 35)
Receiving objects: 100% (144/144), 15.24 KiB, done.
Resolving deltas: 100% (40/40), done.
Cloning into /Users/takayukisugita/.vim/bundle/unite.vim...
remote: Counting objects: 7033, done.
remote: Compressing objects: 100% (3445/3445), done.
remote: Total 7033 (delta 3467), reused 6997 (delta 3435)
Receiving objects: 100% (7033/7033), 865.11 KiB | 273 KiB/s, done.
Resolving deltas: 100% (3467/3467), done.

Installed bundles:
neocomplcache
EnhancedCommentify
yanktmp.vim
vim-matchit
vim-rails
svn-diff.vim
vim-align
vim-rubytest
unite.vim
Helptags: 6 bundles processed
Press ENTER or type command to continue

BundleInstallしただけではプラグインの読み込みはしてくれてないみたいなので、vimを立ち上げ直すとかすると確認できますね。
プラグインの読み込みは

:scriptnames

完了!!

これで環境構築がより簡単に!

自分の変更後のdotfilesはこちら
https://github.com/sugilog/dotfiles

アップデートや削除のための方法も用意されていて、そつがない感じでいいですね。

  • アップデート
:BundleInstall!
  • 個別編集
:Bundles [PluginName]

追記

dotfilesに追加したVundleですが、Vundleの個別の設定が一つで来てしまうみたいなので、githubとかで管理するときには、.gitignoreに以下を追記したほうが良さそう。

dotfiles/.gitignore

.netrwhist