MacOS – vim does not accept syntax in vimrc

macosmacvimsnow leopard

When I put the following in ~/.vimrc and save it,

syntax on

vim get errors while opening. I think there are some vim configuration conflicts. Herewith the errors:

Error detected while processing /Users/Home/.vimrc: line 1: E484:
Can't open file /usr/share/vim/syntax/syntax.vim

I'd appreciate if you can help to get rid of this problem. I'm running osx snow loepard 6.8

Best Answer

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