Using Vim

December 24, 2010

Currently I use textmate as my main editor, but I find myself often using Vim as a secondary editor for small tasks run from the command prompt. I’m thinking about extending my use of VIM for the following reasons

  1. Its available on all the VM’s that I have to use
  2. I really like modal editing

However textmate still has a number of very attractive features that I will want VIM to emulate including:

  1. Excellent markdown support
  2. Good cucumber and rspec support
  3. OK RVM support
  4. ctrl-T find file support

Installing Vim

VIM 7.3 was released recently and is a major upgrade. I want to use this as my command line VIM. Currently I have

➥  vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Feb 10 2010 21:54:21)

➥  which vim
/usr/bin/vim

Getting the latest Vim

This is slightly convuluted, though homebrew makes it reasonably easy (and also has a formula for macvim - mvim). We need

  1. Python:- need a homebrew version of python so we can use homebrew to install pip and mercurial

  2. Pip and Mercurial:- Pip is pythons package manager, mercurial is a great distributed scm (Vim is kept in a mercurial repo)

  3. Vim source:- downloaded using mercurial

    ➥ brew install python

The following from the python install is important

If you install Python packages via pip, binaries will be installed under
Python's cellar but not automatically linked into the Homebrew prefix.
You may want to add Python's bin folder to your PATH as well:
  /usr/local/Cellar/python/2.7/bin

So we add to our shell config (.profile in my case)

# Homebrews python
if [ -d "/usr/local/Cellar/python/2.7/bin" ] ; then
  PATH=/usr/local/Cellar/python/2.7/bin:${PATH}
fi

Now for pip and mercurial

➥  brew install pip && pip install mercurial

Check hg is available

➥  which hg
[andy@92 ~]
➥  source ~/.profile
[andy@92 ~]
➥  which hg
/usr/local/Cellar/python/2.7/bin/hg

Now we can get the vim source

➥  cd ~/install
➥  hg clone https://vim.googlecode.com/hg/ vim

➥  cd vim
➥  ./configure --enable-rubyinterp

Because we are adding the ruby interpreter and because I use RVM we have to be a bit careful otherwise vim won’t link properly. Following this advice made things work nicely.

➥  ./make
➥  ./make install
➥  ln -s /usr/local/bin/vim /usr/local/bin/vi

Sanity checks

➥  vi --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec 24 2010 08:58:02)
➥  which vi
/usr/local/bin/vi
➥  which vim
/usr/local/bin/vim

Installing MacVim

We can have both ;)

➥  brew install macvim