created March 12, 2010 · complexity basic · author Vlad.irnov · version 7.0
Getting Python scripting in Vim on Windows can be a bit tricky, see :help python-dynamic:
- Python must be installed.
- Vim must be compiled with the Python interface (
- The version of Python against which Vim was compiled must match the installed Python version, that is the Python DLL name, such as
You may not need this tip because the two main Windows installers for Vim already have Python support. The most up-to-date Vim version is available from http://sourceforge.net/projects/cream/files/ (Vim without Cream) and has Vim compiled for Python 2.7 (as of version 7.3.829). You may find this tip useful if you want to compile your own Vim on Windows if, for example, you need Vim for a different version of Python.
- Vim version 7.3 is already installed. We only want to replace files
- Python is installed. Let's assume it's Python 2.6 and it is installed in
C:/Python26. The official Python installer from http://www.python.org puts
python26.dllin a directory in the PATH.
Step 1: Install MinGW tools
- Download Automated MinGW Installer (file
MinGW-5.1.6.exe) from https://sourceforge.net/project/showfiles.php?group_id=2435
- Put installer in a separate directory. During installation a bunch of compressed files are downloaded and logs are created. These files will remain after installation is finished and can be deleted.
- Launch installer. Choose Download and Install. Install type: current.
- Choose components to install: MinGW base tools (minimal type of install), MinGW Make, all other are optional.
- Choose install directory. Let's assume it's C:\MinGW. Finish install.
Step 2: Download Vim source files
- Get Vim sources, from whichever source you prefer (the source version should match your currently installed Vim version):
- Getting the Vim source with Mercurial
- https://github.com/b4winckler/vim This is a
gitclone of Vim's official Mercurial repository. This may be the easiest way to get the most recent Vim source with all patches included. You can also select any previous version via branches/tags menu.
- Extract or check out all in one directory, for example C:\devel\vim73.
Step 3 (optional): Edit Vim feature set, apply patches
The NORMAL feature set does not include feature "signs". To include this feature when building NORMAL version of Vim, edit file
add "|| defined(FEAT_NORMAL)" to +signs section.
Alternatively, you could just build with the "HUGE" feature set.
Step 4: Build gvim.exe and vim.exe
Create a batch file called
build_vim.bat, with the following content. Instead of "
C:/Python26" use the directory where Python is installed on your system.
This will build Vim using BIG feature set, no OLE. Adjust options accordingly if you want NORMAL or other feature set.
@echo off REM this file must be run in Vim source directory (e.g., C:\devel\vim73\src) REM these folders and files can be deleted after compilation: /gobj/, /obj/, pathdef.c REM add "bin" directory of MinGW installation to system PATH PATH = %PATH%;C:\MinGW\bin; REM build GUI version (gvim.exe) mingw32-make.exe -f Make_ming.mak PYTHON="C:/Python26" PYTHON_VER=26 DYNAMIC_PYTHON=yes NETBEANS=no FEATURES=BIG gvim.exe > build_vim_log.txt REM build console version (vim.exe) mingw32-make.exe -f Make_ming.mak PYTHON="C:/Python26" PYTHON_VER=26 DYNAMIC_PYTHON=yes NETBEANS=no FEATURES=BIG GUI=no vim.exe >> build_vim_log.txt pause
Move the batch file to the Vim source directory, that is
Run the batch file to build
vim.exe. It takes 4-6 min.
Any errors should appear in the console window. Clean up after script is finished: delete folders "gobj" and "obj", files "pathdef.c", "build_vim_log.txt".
A slightly more sophisticated and more convenient version of the above batch file. It can be run from any directory. It moves freshly built gvim.exe, vim.exe, and the log file to the directory of the batch file, and performs clean up automatically.
@echo off REM ------- specify Vim /src folder ---------------- set VIMSRC=C:\devel\vim73\src REM ------- add MinGW /bin directory to PATH ------- PATH = %PATH%;C:\MinGW\bin; REM get location of this batch file set WORKINGDIR=%~dp0 set LOGFILE=%WORKINGDIR%log.txt echo Vim sources directory: %VIMSRC% echo working directory: %WORKINGDIR% REM change to Vim /src folder cd /D %VIMSRC% REM build GUI version (gvim.exe) mingw32-make.exe -f Make_ming.mak PYTHON="C:/Python" PYTHON_VER=26 DYNAMIC_PYTHON=yes NETBEANS=no FEATURES=BIG GUI=yes gvim.exe > "%LOGFILE%" move gvim.exe "%WORKINGDIR%" REM build console version (vim.exe) mingw32-make.exe -f Make_ming.mak PYTHON="C:/Python" PYTHON_VER=26 DYNAMIC_PYTHON=yes NETBEANS=no FEATURES=BIG GUI=no vim.exe >> "%LOGFILE%" move vim.exe "%WORKINGDIR%" REM clean up: delete /gobj/, /obj/, pathdef.c del pathdef.c del /Q gobj rmdir gobj del /Q obj rmdir obj pause
Step 5: Replace gvim.exe and vim.exe with new files
Shut down all instances of Vim. Navigate to Vim program folder:
C:\Programs\Vim\vim73 or similar. Back up the original
vim.exe: either rename them to
vim_original.exe or move them to another folder.
Copy the new
vim.exe files to the Vim program folder (by copying the files, the default permissions of the folder should be applied to the copies). Start Vim and see if it works:
:version :py print 2**0.5 :py import sys; print sys.version
This is a very ambitious tip! Following are some initial thoughts:
- Our starting point for a "building Vim" tip is Build Vim with your name included (no useful content at the moment).
- Is the following correct: "The official Python installer ... puts python25.dll in %windir%/system32"? Perhaps that is an install option? I have installed Python several times and do not recall it dumping stuff in system32.
- There should be a "clean" option in the makefile that can be used, rather than the advice to delete certain directories (and pathdef.c is in the deleted directory so need to mention it).
- It is not really useful to build Vim without getting the current patches. The correct (and very easy) procedure now is to use the Mercurial repository set up by Bram to hold all the patched source and runtime files. We need documentation on how to do this.
- Using a suitable build from Vim-without-Cream is definitely the best approach for 99% of Windows users. Some hunting around would probably find a version with an old version of Python if required (it would have an older Vim, although one that would be newer than 7.2 with no patches).
JohnBot 06:14, March 30, 2010 (UTC)
What is the github stuff? Björn Winckler is a well known Vimmer, but the github is an unofficial clone of the official release available via Mercurial
, so I don't see why it would be listed first. Also, some explanation is needed: the tip says to select the Vim version via "Switch Tags" but is that really the Vim version? JohnBeckett 10:13, April 4, 2011 (UTC)
- The GitHub mirror looks like the easiest way to download the most recent Vim source with all patches included, as well as any previous 7.x version. Only a web browser is needed. I assume that each tagged snapshot corresponds to Vim 7.x with indicated patches applied, but I cannot prove it. Getting the source from the official Mercurial repo requires installing Hg and figuring out how to use it. (I got the minimum, portable, CLI-only version and it takes up >17MB.) The Gettig_the_Vim_source_with_Mercurial tip is too much for someone who just wants to download the source and is not interested in Mercurial. And it says examples are for Linux. Vlad.irnov 18:42, April 4, 2011 (UTC)