MacOS – E319: Sorry, the command is not available in this version on macvim

macosmacvimvi

While trying to prepare macvim environment to work with clang-format I did:

$ vim ~/.vimrc

map <C-K> :pyf /usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py<cr>
imap <C-K> <c-o>:pyf /usr/local/Cellar/clang-format/2018-04-24/share/clang/clang-format.py<cr>

It worked for vim (on the terminal) but not for macvim, in which, when I hit C-k then I get:

E319: Sorry, the command is not available in this version

There seems to exist approaches to solve this on linux

https://askubuntu.com/questions/284957/vi-getting-multiple-sorry-the-command-is-not-available-in-this-version-af

How to solve this on macOS?

Note: https://github.com/rhysd/vim-clang-format helps by providing :ClangFormat.

Best Answer

It may be because you do not have the correct clang-format.py file downloaded. If vim is compiled using python3 then you need a different file because it is in python2. I downloaded a new python file and changed the key mapping recommended by in the clang python file to the following in my .vimrc:

    map <C-I> :py3file <path-to-this-file>/clang-format.py<cr>
    imap <C-I> <c-o>:py3file <path-to-this-file>/clang-format.py<cr>

This solved the E319 problem I was getting.