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?


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.

  • 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

Since $HOME/_vimrc will be picked up first if it exists, and I don't like to change the stock config file, I just add this line in my $HOME/_vimrc. This way I get my setting done in $HOME/_vimrc, and pick up all the other setting from the installations. And it works even after any reinstall or upgrade.

source $VIMRUNTIME/../_vimrc
  • How exactly is your answer related to a question tagged windows? – Dmitry Grigoryev Mar 23 '16 at 8:41
  • I am not familiar with the software but it might refer to a configuration file? Perhaps the author can clarify? – Burgi Mar 23 '16 at 9:10
  • Okay, my use of $HOME might be questionable but I was talking about windows. On Windows 7 it should be C:\Users\<ID>. The _vimrc under that directory will always be picked up first. – Randy Lei Mar 24 '16 at 3:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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