Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
1  
I expect it has something to do with the fact that you've got a mongrel Cygwin there. Are you certain you need site admin permission to install full Cygwin? You should be able to change the c:\cygwin default to %USERPROFILE%\cygwin or similar, thus avoiding any need for admin permissions. Since Cygwin 1.7, Cygwin doesn't use the registry any more, except for one optional thing for the convenience of setup.exe. You probably need admin perms to install a background service, but Cygwin is plenty useful without those. Cygwin is essentially self-contained. –  Warren Young Jul 30 '12 at 23:04
    
Do you have syntax on somewhere as well? –  Thor Jul 31 '12 at 2:52
    
@Thor: yes, and I manually entered :syntax on and :syntax enable several times. (I'll add that to the question. Thanks.) –  iconoclast Jul 31 '12 at 13:22
    
@WarrenYoung: it's not that I need access permissions on the box, it's that I need managerial permissions. I have the ability to install anything on my box, but it could create a problem. It's not that my manager himself cares, but he has to be prepared to justify anything he gives me permission to install, so if there's a clear explanation as to why I need it, that the Windows IT Nazis can't argue with, then I'm good. (Welcome to the machine.) –  iconoclast Jul 31 '12 at 13:26
    
@WarrenYoung: HOWEVER, if Cygwin is now self-contained, the question may be moot. I think the paranoia here mostly relates to software that changes the registry. So maybe I will be switching to the full version of Cygwin. Thanks for the tip! –  iconoclast Jul 31 '12 at 13:29
add comment

1 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.

share|improve this answer
add comment

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.