Normally for my larger projects I use sublime to fill all my text editing needs. I only really use vim when doing anything over the network or working on smaller projects. Today while practicing with some c in vim, I noticed it wasn't properly highlighting the syntax.
Naturally the first thing I did was :syntax on
but I was getting a strange error
Can't open file /usr/share/vim/syntax/syntax.vim
Some light investigation revealed that I didn't have a syntax.vim
file at that location but instead had one at
/usr/share/vim/vim73/syntax/syntax.vim
I couldn't help but wonder why vim was suddenly looking in the wrong place for the syntax file. I didn't really want to create a symlink to the appropriate directory because it seemed like a stopgap solution. So I went researching and according to the vim documentation $VIMRUNTIME
which should point to the right directory, in this case /usr/share/vim/vim73
instead of /usr/share/vim
. From the documentation, we can see the order in which vim looks for this environment variable:
You don't normally set $VIMRUNTIME yourself, but let Vim figure it out. This is the order used to find the value of $VIMRUNTIME:
1. If the environment variable $VIMRUNTIME is set, it is used. You can use this when the runtime files are in an unusual location.
2. If "$VIM/vim{version}" exists, it is used. {version} is the version number of Vim, without any '-' or '.'. For example: "$VIM/vim54". This is the normal value for $VIMRUNTIME.
3. If "$VIM/runtime" exists, it is used.
4. The value of $VIM is used. This is for backwards compatibility with older versions.
5. When the 'helpfile' option is set and doesn't contain a '$', its value is used, with "doc/help.txt" removed from the end.
So from looking at the directory referenced in the error, it was obvious that it was not reaching step 2. The only explanation was that I must have had set the $VIMRUNTIME variable somewhere. As a matter of fact, in a recent attempt to set vim to be my default editor I added the following to my .bash_aliases
export VIM=/usr/bin
export VIMRUNTIME=/usr/share/vim
export EDITOR=/usr/bin/vim
export VISUAL=/usr/bin/vim
I simply removed line 1 and 2 ($VIM and $VIMRUNTIME) and everything was back to normal.