Install vim on macOS High Sierra using source code

Vim articles

My vim related articles

Install vim from source code

Using git to clone the source code and change directory to vim/src, build the source code using make and then install it into /usr/local/bin.

~$ git clone https://github.com/vim/vim.git
~$ cd vim/src
~$ sudo make 
~$ sudo make install

After above, restart the terminal, run below commands to verify the installation.

~$ vim --version

Output will be something like below

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 24 2018 14:10:16)

macOS version

Included patches: 1-1428

Compiled by xxxx@xxx.local

Huge version without GUI.  Features included (+) or not (-):      

+extra_search      +mouse_netterm     +tag_old_static    

   system vimrc file: "$VIM/vimrc"

     user vimrc file: "$HOME/.vimrc"

 2nd user vimrc file: "~/.vim/vimrc"

      user exrc file: "$HOME/.exrc"

       defaults file: "$VIMRUNTIME/defaults.vim"

  fall-back for $VIM: "/usr/local/share/vim"

Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X -DMACOS_X_DARWIN  -O2   -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       

Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -lintl -framework AppKit   

Check the vim installation path

~$ which vim
/usr/local/bin/vim

Add python support

Download and install python from https://www.python.org/downloads/ 

If you want to add python and python3 support, then the ./configure must be properly applied. 

Run command

cd vim
./configure --enable-multibyte \
--enable-perlinterp=dynamic \
--enable-rubyinterp=dynamic \
--with-ruby-command=/usr/local/bin/ruby \
--enable-pythoninterp=dynamic \
--enable-python3interp=dynamic \
--enable-cscope \
--enable-gui=auto \
--with-features=huge \
--with-x \
--enable-fontset \
--enable-largefile \
--disable-netbeans \
--with-compiledby="shizhen.chn@email.com" \
--enable-fail-if-missing

Option –enable-fail-if-missing is to see the errors for configuration and stop the configuration immediately.

By running above build configuration command, you will see something like below, and the lines with “python” and “python3” are about your python configuration where you can know whether your python paths are correctly configured.

configure: creating cache auto/config.cache

checking whether make sets $(MAKE)... yes

checking for gcc... gcc

...

checking --enable-pythoninterp argument... dynamic

checking --with-python-command argument... no

checking for python2... no

checking for python... /usr/bin/python

checking Python version... 2.7

checking Python is 2.3 or better... yep

checking Python's install prefix... /System/Library/Frameworks/Python.framework/Versions/2.7

checking Python's execution prefix... /System/Library/Frameworks/Python.framework/Versions/2.7

checking Python's configuration directory... /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config

checking Python's dll name... Python.framework/Versions/2.7/Python

checking if -pthread should be used... no

checking if compile and link flags for Python are sane... yes

checking --enable-python3interp argument... dynamic

checking --with-python3-command argument... no

checking for python3... /usr/local/bin/python3

checking Python version... 3.6

checking Python is 3.0 or better... yep

checking Python's abiflags... m

checking Python's install prefix... /usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6

checking Python's execution prefix... /usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6

checking Python's configuration directory... /usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin

checking Python3's dll name... Python.framework/Versions/3.6/Python

...

configure: updating cache auto/config.cache

configure: creating auto/config.status

config.status: creating auto/config.mk

config.status: creating auto/config.h

Then run sudo make && make install  to install vim.

Verify your python is enabled by running command vim --version. You should be able to see +python/dyn and +python3/dyn which means python are enabled.

+comments          +libcall           +python/dyn        +vreplace
+conceal           +linebreak         +python3/dyn       +wildignore

To start over the whole build configuration

cd src && make distclean

To uninstall an existing vim

cd src && make uninstall

MacVim

Sometimes, we also want to use a GUI version of vim on Mac. MacVim is one of the GUI vim on Mac OS. You can clone the source code from Github (https://github.com/macvim-dev/macvim.git), compile and install it. The process is similar as installing vim from source code. Also, you can install it via brew like below.

brew install macvim

By default, your MacVim.app will be install at

/usr/local/Cellar/macvim/<version number>/

For future easier access to it, you can add it to your Applications directory.

Alternatively, you can download the .dmg file from the release page https://github.com/macvim-dev/macvim/releases/ .

 

Advertisement

3 thoughts on “Install vim on macOS High Sierra using source code

  1. Pingback: Mac Vim Usage – Basics – Arophix

  2. Pingback: Mac Vim Usage – Advanced – Arophix

  3. Pingback: Mac Vim Usage – Customization – Arophix

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s