I’m not getting syntax coloring in vim (using Cygwin)

cygwin;vim

I've been so far unable to figure out why vim's syntax coloring is not working for most files, and it's driving me batty.

In case this is relevant: I'm working in Cygwin (more specifically/accurately the bash shell that comes with Git for Windows) because it's the only thing I've been able to smuggle into this Windows shop so far. (I sometimes bring in my MacBook Air but it is somewhat frowned upon. Also, as with most Windows shops they're paranoid about installing software, so a full Cygwin installation would need justification. Also, I'm not using gvim because I prefer to work with vim in a terminal.)

I can get syntax coloring to work if I tell vim that the file is C++

:set syntax=cpp

or if it is a shell script, but not if I'm working in Ruby or PHP.

I've ensured that syntax is turned on with both :syntax on and :syntax enable.

I've tried installing vim syntax files in ~/.vim/syntax/<syntax-type>.vim but this has not made a difference.

I've ensured files had the standard file extension, so if working with a Vagrantfile I tried adding '.rb', and I've tried avoiding my .vimrc file (as well as tried other .vimrc files):

vim -u /dev/null Vagrantfile.rb

I've also ensured Ruby files had the normal 'shebang' line.

Nothing has worked so far.

What could prevent vim from properly coloring certain files?

Best Answer

You have to set vim in the non compatible mode, so it doesn't behave like vi. You should switch syntax on and switch on filetype detection and plugin detection. Here is a minimal .vimrc you can try:

set nocp
syntax on
filetype plugin indent on 

This will make vim behave somewhat nicer and give syntax coloring. But there are a lot more things you could change.

You should install something like pathogen or vundle, so you can easily install new syntax files and other scripts.

Related Question