Compiling Vim

I’ve been using Vim since 2013. It is my main development tool for everything I do, both professionally and personally. I use it along a few plugins and I also add some costume commands, functions, and key binds to my vimrc file.

When I started using Vim I would simply install the vim-gnome package from the Debian repositories. But I like to keep up with the latest features, bug fixes, and improvements of the project. The easiest way to do so is to pull the latest version from the git repository, compile, and use it like that.

Here is what I do.

Get the Source

Vim is nowadays hosted at GitHub. The GitHub issues tracker is also used by the development team there, so if you are interested in contributing for Vim, this would be the place to go.

Since this is a Git repository, to begin we start by cloning the repository:

git clone https://github.com/vim/vim

At this point you might want to checkout a specific tag for a specific version of Vim. According to the Ubuntu 18.04 Bionic Beaver package page, the distributed Vim version for that Ubuntu is v8.0.1453, so you can checkout that tag since we are sure it is stable.

I keep up with the latest version, which would be ahead of version v8.0.1453.

Setup

Once we have the source we need to install a few packages in our system in order to compile Vim.

sudo apt-get install \
    build-essential \
    libncurses5-dev \
    libgnome2-dev \
    libgnomeui-dev \
    libgtk2.0-dev \
    libatk1.0-dev \
    libbonoboui2-dev \
    libcairo2-dev \
    libx11-dev \
    libxpm-dev \
    libxt-dev \
    python-dev \
    python3-dev \
    ruby-dev \
    lua5.1 \
    lua5.1-dev \
    libperl-dev \
    xorg-dev

In the list of packages we have things like build-essential which contains gcc and related tools, the libncurses5-def package which is the library that Vim uses to use ncurses, a few interpreter for python, ruby, etc, and few other things.

All this is necessary for the Vim I used. The Vim installed by the Debian package, gnome-vim, has similar dependencies.

Configuration

To build Vim and make it ready for usage, we run the three usual steps, which are configure, make, and make install. First, here is the configuration I use for my build:

./configure --with-features=huge \
            --enable-multibyte \
            --enable-rubyinterp=yes \
            --enable-python3interp=yes \
            --with-python3-config-dir=/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu \
            --enable-perlinterp=yes \
            --enable-luainterp=yes \
            --with-x=yes \
            --enable-cscope \
            --prefix=/usr/local

First, we have the flag for features. This flag defaults to huge, but we still set it explicitly:

--with-features=huge

There is a very big number of features which can be set or unset with the different values this flag takes. A listing of them is in here. Personally, I just leave the huge to enable everything, since that is what the Debian packages also do.

The next flag is used to compile Vim with multibyte support. This means that Vim will be able to use (natural) languages that need more then one byte per character, like Japanese, Chinese, and so on. Read more about it here.

Even if you only write English, you should still set this flag:

--enable-multibyte

Next we have the interpreter:

--enable-rubyinterp=yes
--enable-python3interp=yes
--with-python3-config-dir=/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu
--enable-perlinterp=yes
--enable-luainterp=yes

I enable the interpreters for Python, Ruby, Perl, and Lua. I also set a specific path for the python interpreter. Without it, Vim could not find it.

We compile Vim with the X Windows System. This enables Vim to use the X’s Clipboard. Without this feature, copy and pasting to and from Vim becomes cumbersome. So we add:

--with-x=yes

Vim comes with support for cscope built in. If you don’t know what cscope is read here. I don’t do much C development nowadays, but still, I like to have this around.

--enable-cscope

Vim installs a few files which it needs at runtime for various purposes. These include, for example, the Syntax files, which set the specific syntax highlighting for each language. They also include the (natural) language files, the files which specify the color themes, and many other things.

The directory where these files is installed is specify by the following flag:

--prefix=/usr/local

The default value of this flag is actually /usr/local. I believe that the Debian package for vim-gnome sets this prefix to /usr/share/vim/vim{VERSION}, since that is where these files show up in my system.

Build and Install

After the configuration is done, we simply run make and make install:

make
make install

You should be able to run vim now.

If you have any issues, such as missing features like the system clipboard, or Vim not being able to use the Python interpreter, check if the configuration flags are correct and if that step succeeds without issues.

Any change to that requires a new execution of make and make install. Just in case, you should also run make clean before.

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: