Here are some notes on how I got YouCompleteMe to work on MacPorts Vim installation. If you have not heard of YouCompleteMe, check out this YouCompleteMe demo really quick. It is a:

fast, as-you-type, fuzzy-search code completion engine for Vim.

Instructions

At a very high level:

  1. Make sure that MacPorts vim and python are found before the OS X versions. This requires updating your PATH environment variable.
  2. python is symlinked to the correct version. python35 in this case.
  3. vim is compiled with Python support. MacPorts does not do this by default.
  4. Install YouCompleteMe.

Detailed instructions provided in the following sections.

My setup at time of writing this post:

Setting up your environment PATH

In order for this to work the MacPorts bin directory has to be high up on the PATH list. The PATH needs to be updated with something like this:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

This will allow for the MacPorts versions of vim and python to be found before the locally installed OS X versions are. There are various ways of doing this, I personally maintain my PATH environment variable in ~/.profile with a block like this in it:

# PATH variable for use with MacPorts.
if [ -f "/opt/local/bin/port" ] ; then
  export PATH=/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:$PATH
  export MANPATH=/opt/local/share/man:$MANPATH
fi

For more on configuring environment variables refer to MacPorts and the Shell.

Installing MacPorts Python

The key takeaway here is using port select to maintain the symlinks pointing the actual versions of python being used.

$ sudo port install python37 py37-pip py37-gnureadline
$ sudo port select --set python python37
$ sudo port select --set python3 python37
$ sudo port select --set pip pip37

In this case executing python and python3 point to the python35 executable. pip is symlinked similarly.

If you are not familiar with port select, try port help select and port select --summary. The latter will provide a list of all MacPorts selection groups.

Installing MacPorts Vim

MacPorts vim does not come with Python support by default. This is simple to remedy using MacPorts variants. Just reinstall Vim with:

$ sudo port install vim +python37 +huge

To get a full list of features that vim is compiled with execute vim --version

Installing YouCompleteMe

Assuming you manage your Vim plugins using something like Pathogen or Vundle, clone the YouCompleteMe repo from GitHub:

$ cd ~/.vim/bundle
$ git clone https://github.com/Valloric/YouCompleteMe.git
$ cd ~/.vim/bundle/YouCompleteMe/
$ git submodule update --init --recursive

Now to install the compiled components of YouCompleteMe. The installation is done with install.py, and not install.sh. The latter is being deprecated and defaults to a Python 2.x installation:

$ ./install.py --clang-completer

Further reading

This post is an elaboration on the following. I found them while trying to figure out how to get YouCompleteMe working on my configuration. Moving to MacVim was not really an option for me:

These may be helpful as well:

  • YouCompleteMe - "YouCompleteMe is a fast, as-you-type, fuzzy-search code completion engine for Vim. It has several completion engines."
  • MacPorts - "The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac operating system."
  • Vim - "Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X."
  • MacVim - "Vim - the text editor - for Mac OS X."