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

8,602

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:
8,602

Related videos on Youtube

iconoclast
Author by

iconoclast

Contractor at Infinite Red, a mobile app & web site design & development company with employees worldwide, experts in React Native, Rails, Phoenix, and all things JavaScript!

Updated on September 18, 2022

Comments

  • iconoclast
    iconoclast over 1 year

    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?

    • Warren Young
      Warren Young almost 12 years
      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.
    • Thor
      Thor almost 12 years
      Do you have syntax on somewhere as well?
    • iconoclast
      iconoclast almost 12 years
      @Thor: yes, and I manually entered :syntax on and :syntax enable several times. (I'll add that to the question. Thanks.)
    • iconoclast
      iconoclast almost 12 years
      @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
      iconoclast almost 12 years
      @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!