Vim is a powerful text editor, which can be scaled up to a fully-fledged IDE, especially for Python. Though, if you are reading this blog post, I guess that you already know what Vim is and I do not have to tell you about it. What I want to share though, is how to build Vim with Python 3 on macOS, when using Anaconda Python 3. If you want to use some nice plugins of Vim for Python (e.g. Pymode), then your Vim should have only Python 3 enabled. That is, you should have: 

-python
+python3

There are some solutions out there with MacVim, proposing different tricks to enable Python 3 of MacVim when Vim starts. I haven’t tried any of those, but I doubt of their functionality. So, if you agree with me up to here, then you also have tried to build Vim on your macOS. And, I guess, when you are trying to check if your Vim has properly functioning support of Python 3, by (e.g.) doing :py3 pass, then you get the super informative error: 

Vim: Caught deadly signal ABRT
Vim: Finished

Abort trap: 6

I struggled with this almost a week, and even at the GitHub of Vim cannot provide the solution. But, I finally found the solution and I want to share it, so other people will be helped.

I will not go into the details of the flags that one can use when configuring the building process of Vim. You can check what flags are there by using the --help argument of the configure script. I will use some simple flags and describe the process, so you can have a fully Python 3 built Vin on your macOS.

So, let’s go!

  1. Download the latest stable version of Vim. You can find that by either checking the GitHub repo of Vim or going to the download page of Vim. At the moment of this blog post, the latest stable version of Vim is 8.2. Download and expand the code of the latest stable version of Vim, and then open your terminal and navigate inside of the directory of the code of Vim. I will refer to this directory as vimroot for the rest of this text. 
  2. On your terminal and in the vimroot directory. First issue the command:
    $ export CPPFLAGS=-I/Users/< your home directory >/opt/anacoda3/include/python3.7m
    Then, configure your Vim building process by, e.g., using:
    $ ./configure --enable-python3interp=yes \
    --prefix=< vim installation path > \
    --enable-fail-if-missing \
    --with-vim-name=< optional, name/name prefix for vim binaries >

    As prefix, you can use the /usr/local.

    As name for Vim, you can use the version, for example at the moment of writing this, I use the vim.8.2.0.

    Then, hit enter and wait a bit.

  3. After the configuration is over, then is the tricky part. Now you have to make available to the building process, the shared libraries for Python. The Vim building process, tries to find those at /usr/local/lib. To make them available, you have to issue the command:
    $ sudo ln -s ~/opt/anaconda3/lib/libpython3.7m.a /usr/local/lib/
    and
    $ sudo ln -s ~/opt/anaconda3/lib/libpython3.7m.dylib /usr/local/lib/
  4. Then, you can issue
    $ make
    followed by
    $ sudo make install

You can validate that your building is correct by opening your newly built vim with

$ vim --clean

and then issuing

:py3 pass

or

:py3 print(‘OK’)

in Vim. Hopefully, all will be OK! 

Enjoy your Vim with anaconda Python 3, on macOS!