If you want the most up-to-date version of Vim, you can download the source files and compile it on your computer. This ensures you have the latest version of Vim.

Building Vim from source is not hard. And if you need a certain patch for vim, it's actually easier to compile from scource than to patch your current Vim version provided by your package manager.

Before we start

First you'll want to remove Vim if you have it installed on your system (and havn't build your current version from source, in which case you can just update it as explained below). Remove Vim by running

$ sudo apt-get remove vim vim-runtime gvim

If you have the following packages also installed, remove them too

$ sudo apt-get remove vim-tiny vim-common vim-gui-common

Get dependecies

Programs often need routines, such as input/output for example, which are stored in shared libraries. If a program requires a shared resource, we say it has a dependency. To satisfy the build dependencies for the Vim source package, we run

$ apt-get build-dep vim-gnome

Possibly you need to run this with administrative privileges (i.e. use sudo).

Get the Vim source code with Mercurial

By convention, we'll first create a directory for our source code named src and then download the source code into it with Mercurial

$ mkdir -p ~/src/hg
$ cd ~/src/hg
$ hg clone https://vim.googlecode.com/hg/ vim

Building the program

Change to the directory with the vim source files and run make to build the program

$ cd ~/src/hg/vim
$ make

This will produce a lot of messages and can take a while depending, among other factors, on the performance of your processor.

Installing the program

Well-packaged source code often includes a special make target called install. This target will install the compiled program in a system directory for use. This directory is usually /usr/local/bin, the default location for locally built software. Run the following to finish the installation of Vim

$ make install

We can check if the program is ready to use

$ which vim

Installing new patches/updating

From now on, if you want to get new patches, you simply need to check for any changes to the vim source by changing to the directory with the Vim source code and running

$ hg pull
$ hg update

Finish again by running

$ make
$ make install

Why did I built Vim from source?

I used this method to make use of the breakindent patch, as mentioned here. In short, this enables proper line wrapping by also taking the indentation of the line into account. My current Vim version was 7.4 and only included patches 1-52 while the breakindent patch was introduced in patch 7.4.338. After compiling from source, I'm currently running Vim v7-4-801 which was released july 28 this year (one month ago).

See Also/References