Cygwin: Using programs already installed in Windows


I just installed Cygwin and I'm a bit confused about how it works. I see I have a "home" folder in C:\cygwin\home. I've already installed and set up Mercurial, Vim, Git, etc. on my Windows machine using their respective installers. How do I let Cygwin use those programs, and also their config files (_vimrc, etc.) ?

Best Answer

Cygwin is intended primarily to provide a Linux-like environment on top of Windows. It works best with programs that are compiled for Cygwin. It can work directly with native Windows programs, but you have to be careful.

One feature of Cygwin is that it tries to make the Windows file system look like a typical Linux file system, e.g., programs are under /usr/bin. Cygwin programs don't refer to the C: drive, they refer to /cygdrive/c. (Some Cygwin programs understand "C:" but those are the exception.) While your home directory appears under C:\cygwin\home from Windows, it appears under /home from Cygwin. That means that passing full path names between Cygwin programs and Windows programs can be tricky: Windows programs don't understand Cygwin full path names and Cygwin programs generally don't understand Windows full path names. There's a Cygwin utility, cygpath, that can translate between Windows and Cygwin paths, but you do have to insert that level of translation yourself as necessary.

I don't know of a general solution to the problem of interfacing Cygwin programs with Windows programs. The best solution depends on what you're trying to do, on how much you want to live in the Linux world vs. living in the Windows world, and on the programs you need to use.

If you're planning to use Mercurial, Vim, Git, etc. from the Cygwin command line, I would recommend installing the Cygwin versions of those programs. You can have both Windows and Cygwin versions on your system, but you have to be careful with your PATH.

I tried configuring Windows gvim to use the Cygwin shell and finally gave up. I now use Windows gvim when opening files from the GUI and Cygwin vim when opening files from the command line. There are just too many places within Windows Vim where conventions of the Windows OS API have to be matched to the Cygwin conventions of external programs. That said, using the same user configuration files for both is easy. In a Cygwin bash shell:

ln -s /cygdrive/c/Documents\ and\ Settings/username/_vimrc ~/.vimrc
ln -s /cygdrive/c/Documents\ and\ Settings/username/vimfiles ~/.vim

You just have to make sure that all those files have Unix line endings and use d2u on those that don't. Cygwin's Vim (any Unix Vim) expects Unix line endings; Windows Vim accepts either Unix or DOS line endings.

I have used Cygwin quite a bit, but I'm not an expert. The above just reflects my experiences.