Compile Vim With Ruby & Python Support on OS X

Compile Vim with Ruby & Python

Vim can be extended with Ruby and Python if it’s compiled with the +ruby and +python features. If you are using MacVim, you already have them, so you can continue using it happily. But the terminal Vim that comes with your OS X does not support them. Fortunately, we can fix that in less than 5 minutes.

The process is similar to what we described in Fixing the MacVim Cursor Bug on MBP Retina, but this time it’s for the terminal Vim.

If you are a Homebrew user, you can install a new version of Vim by typing the following commands in your terminal:

1
2
$ brew install mercurial
$ brew install https://raw.github.com/gist/3760533/74dd7bf6647c927c782b1cd9ff99e22161e375e9/vim.rb

If you want different compile options, you can fork the gist and customize it as you wish.

If you don’t use Homebrew, you can still compile it by your own. You need mercurial in order to clone the Vim repository. After that, everything is quite straightforward:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ cd /tmp
$ hg clone https://vim.googlecode.com/hg/ vim
$ cd vim
$ hg update -c 1e22adc6176e
$ ./configure --prefix=/usr/local \
              --enable-gui=no \
              --without-x \
              --disable-nls \
              --enable-multibyte \
              --with-tlib=ncurses \
              --enable-pythoninterp \
              --enable-rubyinterp \
              --with-ruby-command=/usr/bin/ruby \
              --with-features=huge
$ make
$ sudo make install

Please note that we are installing Vim in /usr/local/bin, so it has to be included in your PATH before /usr/bin, where the old terminal Vim is located. You can easily accomplish this by adding the following line in your .bashrc or .zshrc:

1
2
3
# .bashrc or .zshrc

export PATH=/usr/local/bin:$PATH

That’s it! Your Vim with Ruby & Python support is ready for some action.

About the author

Veselin Todorov is a software consultant focused on testing, code quality and building awesome products. He is helping companies to ship their products with confidence and style.

If you are passionate about JavaScript, Node.js, TDD, building and growing applications, you should visit his blog at RobustJS.com