Build Vim from source natively on Windows 7, Windows 8.1, and Windows 9 Windows 10

Realizing my version of Vim on Windows was quite stale, I decided to build it myself from source. On Windows 8.1. How hard could it be?

Well, it’s actually pretty easy once you have the right tools. I kept running into out-of-date documentation, so I’ll try to keep this future-compatible by explaining what you need for a frustration-free experience. A complete working project is also available at https://github.com/mgiuffrida/vim.

Instructions updated 1/28/2017 for Vim 8.0 and confirmed on Windows 10.

Get the tools

You’ll want to grab a recent edition of Visual Studio for its compilers. I’d recommend getting a recent free edition like the Express for Windows Desktop or Community editions.

You’ll also need the Windows SDKs as they don’t ship with Visual Studio anymore. The SDKs provide header files we need to compile.

First, download the Windows 7 SDK, even if you’re on Windows 8.1/10, because it has a file we need. If you’re using Windows 8.1/10, you can download the Windows 8.1 SDK as well if you like. In any case, only install the Windows SDK proper; you don’t need to install the other stuff, like the .NET SDK or the Performance Toolkit.

Get the source

Vim now lives on GitHub, so get the source with

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

Configure the build

Let’s make a batch file alongside the vim directory called configure.cmd (or download here):

@echo off

:: Windows SDK Include directory. No quotation marks.
set SDK_INCLUDE_DIR=C:\Program Files (x86)\Windows Kits\8.1\Include

:: Visual Studio directory. Quotation marks.
set VS_DIR="C:\Program Files (x86)\Microsoft Visual Studio 12.0"

:: Target architecture, AMD64 (64-bit) or I386 (32-bit)
set CPU=AMD64

:: Toolchain, x86_amd64 (cross-compile 64-bit) or x86 (32-bit) or amd64 (64-bit)
set TOOLCHAIN=x86_amd64

:: TINY, SMALL, NORMAL, BIG or HUGE. NORMAL or above recommended
set FEATURES=BIG

:: yes for gvim, no for vim
set GUI=yes

:: Whatever IDE integrations we don't need
set NETBEANS=no

:: UTF-8 encoding
set MBYTE=yes

:: Enable Python scripting
set DYNAMIC_PYTHON=yes
set PYTHON=C:\Python27
set PYTHON_VER=27

echo "Configuring Visual Studio..."
call %VS_DIR%\VC\vcvarsall.bat %TOOLCHAIN%

If you’re using the Windows 8.1 SDK, you’ll also need Win32.Mak, an options file for nmake. This file ships with the Windows 7 SDK, so you can simply copy it from 7.0\Include\Win32.Mak to 8.1\Include\WIn32.Mak.

Update the directories if necessary, and set your desired features. You can find more options in vim/src/Make_mvc.mak. In addition to Python, you can link with Python3 (but not both), Ruby, Perl, and more.

CPU specifies your target architecture, and TOOLCHAIN specifies how to compile:

  • For a 32-bit version: CPU=I386 and TOOLCHAIN=x86
  • For a 64-bit version: CPU=AMD64 and TOOLCHAIN=x86_amd64

You can build either version, but the 64-bit version will only run on a 64-bit machine. It’ll be capable of handling multi-gigabyte files, which is nice, and may run slightly faster. (On a 64-bit machine, you could also use the native amd64 toolchain if your version of VS has it, but it really doesn’t make a difference.)

If you link to a third-party library like Python, be sure you have the appropriate version (32-bit or 64-bit).

Build Vim!

Now create build.cmd alongside the vim directory (or download here):

pushd vim\src
if /i [%1] == [clean] (
  call %VS_DIR%\VC\bin\nmake -f Make_mvc.mak clean
) else (
  call %VS_DIR%\VC\bin\nmake -f Make_mvc.mak
)
popd

Invoke configure once, then invoke build to compile vim.exe or gvim.exe, depending on the value of GUI.

Any time you change the values in configure.cmd and re-run configure, run build clean before building again.

Install Vim

First, you need to copy the executables, docs, etc. to a directory named vim80. (The numbers should match the output of vim --version.) Create a script named copy-vim.cmd (or download here):

@set SRC=vim
:: DEST must match version number in order to run install.exe
@set DEST=vim80

xcopy %SRC%\runtime %DEST% /D /S /H /I /Y
xcopy %SRC%\src\xxd\xxd.exe %DEST% /D /Y
xcopy %SRC%\src\GvimExt\gvimext.dll %DEST% /D /Y
xcopy %SRC%\src\*.exe %DEST% /D /Y

copy-vim will place everything you need in vim80. You can stop here, if you’d like.

vim80\install.exe will run a command-line “installer”. Use the given numbers to disable actions you don’t want—I disabled 10 (create startup file), 14 (context menu), and 17–19 (desktop icons). Enter d to perform the actions, and you should be all set.

If you want to install the batch files to launch Vim in the default location (C:\windows), you’ll need to run install.exe as an administrator. You can open the Command Prompt from the Start menu as an administrator by holding Ctrl+Shift, or just right-click install.exe and choose “Run as administrator”. You could also install to somewhere else in your PATH.

Troubleshooting

configure.cmd

The input line is too long. The syntax of the command is incorrect.

Visual Studio is kind of silly—it will repeatedly add stuff to your PATH until it becomes too long to work. Just close and re-open the Command Prompt and run configure from scratch.

The specified configuration type is missing. The tools for the configuration might not be installed.

Your VS installation doesn’t include the TOOLCHAIN you’re trying to use, so vcvarsall.bat is unable to find the correct vcvars[toolchain].bat file. E.g., Visual Studio Express may only include x86 and x86_amd64 (to cross-compile for AMD64 using the x86-amd64 toolchain). Try setting TOOLCHAIN to x86_amd64 if you want a 64-bit build, or x86 otherwise:

Your CPU %CPU% %TOOLCHAIN% Output
64-bit AMD64 amd64 64-bit
any AMD64 x86_amd64 64-bit
any I386 x86 32-bit
64-bit I386 amd64_x86 32-bit

copy-vim.cmd

Sharing violation

Did you close Vim before running vim-copy?

:help content missing, runtime files not loading

If :help works when running Vim or gVim from the src directory (vim\src) but not from your vim80 location, be sure the contents of vim\runtime are being copied to vim80 via copy-vim.cmd.