Compile VIM from source for MacOS Monterey 12 or MacOS Ventura 13

Nov 22, 2022

Introduction

Starting MacOS 12, python2 has been deprecated from the system applications and VIM requires python2 or python3 support for some of the plugins to work properly, like ultisnips, etc., When I tried to compile VIM from source, python3 from the system applications wouldn’t get compiled along with it for some reason.

The easiest solution would be install python3 using homebrew and compile VIM with it, but you have to make this the default python for the whole system or atleast configure it in VIM using vimrc, which didn’t sit well with me, so I decided to do my own research and came across a solution to compile VIM with system default python3 but it requires a bit of patience and editing skills.

Finding the xcode-installs directory:

Fire up the terminal and type xcode-select -p

% xcode-select -p
/Library/Developer/CommandLineTools

Python3 Config files path

In the terminal

% python
Python 3.9.6 (default, Aug  5 2022, 15:21:02)
[Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python39.zip', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages']
>>>

Vim by default looks for a different runtime path for python3 looking in all default folders and fails to link python causing all python based plugins to not work properly.

Compiling VIM:

# here we are copying and pasting the python src path which we found out above
./configure --enable-largefile --enable-libsodium --enable-darwin --enable-cscope --enable-autoservername --enable-perlinterp=yes --enable-python3interp=yes --enable-rubyinterp=yes --enable-terminal --with-features=huge --with-python3-command=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3 --with-python3-config-dir=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/config-3.9-darwin
PYTHON3_LIBS    = -L/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/config-3.9-darwin -lpython3.9 -ldl -lSystem -framework CoreFoundation
# Here we are adding runtime path for vim to look into the new xcode-select directory, which will show the python3 to vim
PYTHON3_LIBS    = -L/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/config-3.9-darwin -rpath /Library/Developer/CommandLineTools/Library/Frameworks/ -lpython3.9 -ldl -lSystem -framework CoreFoundation

Vim will be compiled with MacOS default python3.


   macos-12 (1) , macos-13 (1) , ventura (1) , monterey (1) , macos (1) , vim (2)