A quick and dirty fix is to create the missing file with contents:
" Vim syntax support file
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2001 Sep 04
" This file is used for ":syntax on".
" It installs the autocommands and starts highlighting for all buffers.
if !has("syntax")
finish
endif
" If Syntax highlighting appears to be on already, turn it off first, so that
" any leftovers are cleared.
if exists("syntax_on") || exists("syntax_manual")
so <sfile>:p:h/nosyntax.vim
endif
" Load the Syntax autocommands and set the default methods for highlighting.
runtime syntax/synload.vim
" Load the FileType autocommands if not done yet.
if exists("did_load_filetypes")
let s:did_ft = 1
else
filetype on
let s:did_ft = 0
endif
" Set up the connection between FileType and Syntax autocommands.
" This makes the syntax automatically set when the file type is detected.
augroup syntaxset
au! FileType * exe "set syntax=" . expand("<amatch>")
augroup END
" Execute the syntax autocommands for the each buffer.
" If the filetype wasn't detected yet, do that now.
" Always do the syntaxset autocommands, for buffers where the 'filetype'
" already was set manually (e.g., help buffers).
doautoall syntaxset FileType
if !s:did_ft
doautoall filetypedetect BufRead
endif
which is valid (at the very least) for vim
7.0 through 7.3, as the file hasn't changed in years.
If you take a closer look, though, it is quite surprising that vim
tries to open /usr/share/vim/syntax/syntax.vim
: I checked the path of syntax.vim
on different OS X versions and this is what I got:
OS X 10.8.3 "Mountain Lion"
/usr/share/vim/vim73/syntax/syntax.vim
Mac OS X 10.5.8 "Leopard"
/usr/share/vim/vim70/syntax/syntax.vim
/usr/share/vim/vim72/syntax/syntax.vim
I'd expect Mac OS X "Snow Leopard" to follow a similar pattern, so why is the path different? What has changed in vim
, have you compiled a newer version or replaced it?
It could also be that /usr/share/vim/vim<version>/syntax/syntax.vim
exists, in which case, as an alternative, you could create a link:
sudo mkdir -p /usr/share/vim/syntax/
sudo ln /usr/share/vim/vim<version>/syntax/syntax.vim /usr/share/vim/syntax/syntax.vim
Best Answer
There are two common methods:
Method 1: One of the easiest and most commonly recommended methods is by creating a file called
.vimrc
in your home directory. The one and only command you need to run isecho syntax on >> ~/.vimrc
. The next time you access a non-txt file with vim, you will notice highlighted text.Method 2: Another method, one that I personally use/used, is by installing "vim --override-system-vim". First run
vim --version
in the terminal. Notice the +(s) and -(s) and keep it in mind, maybe even take a picture. Next we will install a package manager, if one is not already installed on your computer. We will use Homebrew for this tutorial. Runxcode-select --install
in the terminal. It will take about 10-15 min to install the Xcode Command Line Tools. Once the installation is complete, runruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
. After brew has installed, runbrew doctor
to make sure that everything is in working order. If it recommends you run any commands to resolve an issue, run them first before continuing. After the previous step is complete, runbrew install vim --override-system-vim
. After vim is installed, runvim --version
and notice the difference of the +(s) and -(s) in comparison to when you first ran the command. Not only has syntax highlighting been enabled, but there are other features that have been enabled as well.