Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My GVIM 7.3.46 install on Windows XP Professional SP3 32bit does not perform syntax highlighting if there exists a _vimrc file, at least not PHP and C. Even explicitly mentioning set syntax=php I get not highlighting, whether or not the filename extension ends in .php.

Even if there is a 0-byte blank file in C:\Documents and Settings\myUsername\_vimrc then files will not be syntax highlighted. I can rename that 0-byte file to _vimrcBLAH and syntax highlighting works again.

What might cause this, and how might I fix it?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

The gvim program alone does not have syntax highlighting enabled by default. Syntax highlighting is only enabled by explicitly enabling it with a command such as :syntax on. So the only way to have syntax enabled is to enable it yourself at the Vim command line or to have such a command in a configuration file that's read on startup.

Vim is typically installed on Windows with a standard set of configuration commands in C:\Program Files\Vim\_vimrc. That standard set includes syntax on. Without any other configuration files, gvim will read that file on startup and you will have syntax highlighting.

In :help _vimrc it says, "Four places are searched for initializations. The first that exists is used, the others are ignored." The list of user vimrc files includes $HOME/_vimrc followed by $VIM/_vimrc. On your system, $VIM is C:\Program Files\Vim.

So, when you use a C:\Documents and Settings\myUsername\_vimrc file, gvim reads that file and skips C:\Program Files\Vim\_vimrc. If your _vimrc does not contain syntax on you will not get syntax highlighting.

If your are going to use your own _vimrc, then make sure you copy into it from C:\Program Files\Vim\_vimrc any of those configuration commands you need, including syntax on.

share|improve this answer
    
Thank you Gary! This is exactly what I needed to know. I'm rather glad to know that the answer is in the fine manual, I'm going to go through it later today. Thanks! –  dotancohen Apr 17 '12 at 16:58
    
Thank you for that. How odd that gvim 7.3 on Linux seems to default this to on (I can't find syntax on in any of the .vimrc or .gvimrc files on my Linux system), but gvim 7.3 on Windows doesn't. –  T.J. Crowder Jul 20 '12 at 13:54
    
@T.J.Crowder: The set of files discussed in the answer are referred to as personal initialization files. Before loading one of those, Vim searches for and loads a system initialization file. (See :help startup.) A standard Vim installation on Windows has a personal initialization file at $VIM/_vimrc but no system initialization file, so your $HOME/_vimrc is loaded instead of $VIM/_vimrc. A standard Vim installation on a Linux distribution has a system initialization file usually at $VIM/vimrc which is always loaded before and in addition to the personal initialization file. –  garyjohn Jul 20 '12 at 15:04
    
@T.J.Crowder: So you will find a syntax on command in the system initialization file on your Linux system, probably in /usr/share/vim/vimrc or /etc/vimrc. The location is given in the output of the :version command. –  garyjohn Jul 20 '12 at 15:06
    
@garyjohn: Right, I looked in those as well before posting the above. I can't find one in any of them. I've looked in any .vimrc, .gvimrc, and gvimrc file I could find under both $VIM and $HOME. –  T.J. Crowder Jul 20 '12 at 15:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.