Compiling Vim

Share on:

"Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X."

This tutorial covers the steps required to compile Vim from source with Python support (i.e. python3.x). If you use ChromeOS or a Linux distribution, it may not necessarily have access to the latest build of the application. To get past this issue, compiling from source provides the best approach. Learn how to build Vim, so understand how to enable example packages needed for plugins based on Python.

Vim Configuration

This is a really quick guide to configuring Vim

  • Check the Vim version
  • Remove unnecessary packages
  • Install the require packages
  • Get the Vim source code
  • Build the source code
  • Test the generated package

Which version of Vim

In this blog post I am using Vim. In most instances you should not have to update the version of Vim on your host. If you use certain plugins e.g. YouCompleteMe, they will complain if you do not have a current version of Vim.

Build from Source

Building from source is well documented.

Reference:

  1. Check the Vim version

    1vim --version
    
  2. Install Packages

    Get rid of the existing Vim

    1sudo apt autoremove vim vim-runtime gvim
    

    Get rid of the deprecated python 2.x

    1sudo apt autoremove python2*
    

    Add build packages

    • git
    • libatk1.0-dev
    • libcairo2-dev
    • libgtk2.0-dev
    • liblua5.1-0-dev
    • libncurses5-dev
    • libperl-dev
    • libx11-dev
    • libxpm-dev
    • libxt-dev
    • lua5.1
    • python3-dev

    NOTE: Expand the code below if you get an error!

     1sudo apt install -y git \
     2                 libatk1.0-dev \
     3                 libcairo2-dev \
     4                 libgtk2.0-dev \
     5                 liblua5.1-0-dev \
     6                 libncurses5-dev \
     7                 libperl-dev \
     8                 libx11-dev \
     9                 libxpm-dev \
    10                 libxt-dev \
    11                 lua5.1 \
    12                 python3-dev \
    13                 ruby-dev 
    
  3. Move to the home folder

    1cd ~
    

    Ref: VIM

  4. Get VIM from github

    1git clone https://github.com/vim/vim.git
    
  5. Enter the archive directory

    1cd ~/vim
    
  6. Set the Python configuration e.g.

    1PYTHON_VER=$("echo $(python3-config --configdir) | awk -F '/' '{print$4}'")
    

    NOTE: Python Dev comes with a utility to indicate the correct path e.g.

    1python3-config --configdir
    

    Will output the Python path

    1/usr/lib/python3.11/config-3.11-x86_64-linux-gnu
    
  7. Add configuration

     1./configure --with-features=huge \
     2--enable-multibyte \
     3--enable-rubyinterp=yes \
     4--enable-python3interp=yes \
     5--with-python3-command=$PYTHON_VER \
     6--with-python3-config-dir=$(python3-config --configdir) \
     7--enable-perlinterp=yes \
     8--enable-gui=gtk2 \
     9--enable-cscope \
    10--prefix=/usr/local
    
  8. Compile the source and install

    1make && sudo make install
    
  9. Confirm the Vim configuration and grep on Python3 support (i.e. +Python3)

    1vim --version | grep +python3
    
  10. Add the vim command as an Alias to ~/.bashrc

1alias vi="/usr/local/bin/vim"

Congrats! You have a custom build of Vim.