John Robinette

Compiling Vim on Windows

Getting Started

So you've given Vim a try and have gotten all those commands engrained into your memory. Or at least, you're hooked to the point of wanting to use Vim for some more stuff. But then you discover that one of the features you need doesn't work. For me, both the Python and TCL libraries that the official Vim download uses were older than the ones on my computer. Because the support for these languages depended on the older versions, Vim wasn't able to support them on my computer out-of-the-box, and installing older versions of the languages just so the editor will work seems silly. So I did what any sensible person would do and decided to build my own. The following process will be fairly specific to the issues I ran into building Vim to my needs, but it should be useful to just about anyone wanting to compile Vim on Windows (if you're compiling on a UNIX-like system, I expect you can do it without help).

Before we can actually do any building, you need to download the appropriate files. This includes any languages you want compiled in (I included Python, Perl, TCL, and Ruby), plus the tools to build Vim and the Vim sources. I'll assume you can isntall the languages and add them to your PATH yourself, so I'll only go through getting the Vim stuff working.

A successful installation of Cygwin or MinGW should give you access to the GNU Compilers (gcc and g++) and the GNU make utility from the windows command prompt. If you type those commands and get a "...is not recognized as an internal or external command..." error, then please check the documentation for your repsective tool on how to set up the PATH environment variable to work with your tool.

Prepare to Build

  1. Unzip the Vim sources to a location on your hard drive. For the rest of this HowTo, I'll assume you used C:\, so you'll have a folder called C:\vim, C:\vim\vim71, and so on.
  2. Open a Windows Command Prompt and type:
    cd C:\vim\vim71\src
    If you unzipped to another location, use that path instead of what I provided here, so long as you get to the src directory.
  3. You need to edit the Makefile you'll be using. You can use Notepad if you have nothing else, but if you have the official Vim package that will probably be easier to use. If you're using Cygwin, edit the "Make_cyg.mak" file. If you're using MinGW, edit the "Make_ming.mak" file. For the rest of this tutorial I'll only reference the Cygwin file, so if you're using MinGW, just replace "Make_cyg.mak" with "Make_ming.mak" at the appropriate places.
  4. Find and edit the following settings:
    GUI=yes
    PERL_VER=56
    DYNAMIC_PERL=yes
    PYTHON_VER=25
    DYNAMIC_PYTHON=yes
    TCL_VER=84
    DYNAMIC_TCL=yes
    RUBY_VER=18
    RUBY_VER_LONG=1.8
    DYNAMIC_RUBY=yes
                    
    Those will set you up for Perl version 5.6, Python version 2.5, TCL version 8.4, and Ruby version 1.8. If you are using different vesions, just replace the appropriate version number with what you have. We've also ensured that building the GUI version is the default. Some people will argue that we could have included all of this on the command line when we run make, and while that's true, I'd rather not have to type all of that every time, so I like to edit the Makefile to have the defaults I want.
  5. If you're going to build against Ruby, there's one more thing we must change before you can successfully build Vim. Locate the Ruby include files for your distribution and open the file config.h. For me, this was:
    C:\ruby\lib\ruby\1.8\i386-mswin32\config.h
    At the top of this file, you'll see three lines like follows:
    #if _MSC_VER != 1200
    #error MSC version unmatch
    #endif
    These commands prevent this file from being used by any compiler aside from a Microsoft compiler of a certain version or higher. Since we aren't using a Microsoft compiler, this will always fail and prevent us from building Vim. Comment out those lines with /* */, as follows:
    /*#if _MSC_VER != 1200
    #error MSC version unmatch
    #endif*/

Build Vim

  1. If you're using Cygwin, type bash at the command prompt to load a BASH shell. Then, type the following:
    make -f Make_cyg.mak gvim.exe \
    PERL=C:/perl \
    TCL=C:/TCL \
    PYTHON=C:/Python25 \
    RUBY=C:/ruby
                    
    Replace the paths given for the programming languages with the path to your installation of the language. While you could also specify these in the Makefile, I think it's useful to keep simple options like these present on the command line so you have at least a little idea of what's being built. Besides, what if you want to build again and decide to drop TCL? If you do it this way, just don't provide a path and it won't be included. Note that the \ simply tells BASH that we're continuing the command on the next line. This could all be put on one line.
  2. This build didn't include the Vim OLE support. If you want that, add
    OLE=yes
    to the preceding make command.
  3. To build a command line version:
    make -f Make_cyg.mak vim.exe \
    GUI=no \
    PERL=C:/perl \
    TCL=C:/TCL \
    PYTHON=C:/Python25 \
    RUBY=C:/ruby
                    
    The differences should be fairly obvious. We tell it to build the target vim.exe with no GUI, but otherwise everything is the same.

Installing Your Custom Vim

  1. If you already have a pre-built version of Vim 7.1 build, just copy your custom gvim.exe and/or vim.exe to your Vim installation directory.
  2. If you don't have an installation already present, then first extract the Vim 7.1 Runtime Files. I extracted mine to the "Program Files" directory, which game me the following setup:
    C:\Program Files\vim
    C:\Program Files\vim\vim71
                    
  3. Now copy your gvim.exe and/or vim.exe into the vim71 directory and you should be set!
  4. You'll probably also want to clean up after yourself to free up the disk space used by the build:
    make -f Make_cyg.mak clean
                    
    Just make sure you've moved your gvim.exe and/or vim.exe before you do this!