Checking for Python version and Vim version in your .vimrc

Recently I’ve had to adjust a bunch of my dotfiles to support some old (Centos 5) systems which means that I am using a Vim that has Python 2.4 build in… needless to say, it breaks some of my dotfiles 😉

So here’s some tips on patching Vim version issues.

First, checking if you have Python in your Vim and which version you are using. It returns a version similar to how Vim does it with it’s version. So 204 is the result for Python 2.4, 207 for Python 2.7 and so on.

" Check python version if available
if has("python")
    python import vim; from sys import version_info as v; vim.command('let python_version=%d' % (v[0] * 100 + v[1]))
    let python_version=0

Now we can make plugins/bundles dependend on versions:

if python_version >= 205
    " Ultisnips requires Vim 2.5 or higher due to the with_statement
    Bundle 'SirVer/ultisnips'
    Bundle "MarcWeber/vim-addon-mw-utils"
    Bundle "tomtom/tlib_vim"
    Bundle "garbas/vim-snipmate"

And checking for the Vim version to see if features are available:

if version >= 703
    set undofile
    set undodir=~/.vim/undo
    set undolevels=10000

    call system('mkdir ' . expand('~/.vim/undo'))

That’s it, the examples can be found in my Vim config:

Bookmark and Share


About Rick van Hattem

Rick van Hattem is a Dutch Internet entrepreneur and co-founder of
No comments yet.

Leave a Reply