Distributing configuration files 2: Cygwin hassles and Vim

Today’s topic is the first continuation of Distributing configuration files and as the title already denotes, it is concerned with Vim, specifically with using it in heterogenous environments (read: Linux and window$/Cygwin).

Unfortunately, the window$ version of Vim searches different paths for configuration files than the Linux version does. That means that even though there probably is a git version for window$, it won’t help us much as window$ doesn’t know softlinks. So we must use a little trick…

When I’m forced to work under window$, I install Cygwin to make the work a lot more enjoyable. It has packages for practically everything I need, the most important of which is a usable terminal. Unfortunately, the Linux file system it simulates conflicts with window$’ own one, so there typically arise problems when using an editor started from this environment.

To make things worse, Cygwin has problems with ntfs’ file properties (ownership and access rights) and with handling the different line endings of Linux and window$ files. Therefor, I prefer installing the window$ version of Vim which does not suffer from these problems. Of course, I still want to use the same settings for it that I use on my PC at home…

Coping with textmode hassles

This is very important! You need to make sure that the directory you check your settings out to is mounted in binary mode. Otherwise, you won’t get much further than checking out: The first commit, branch or tag you do will completely screw up your git directory as it cannot deal with textmode’s line endings (aka <CR><LF> instead of just <LF>, check out the Cygwin website for details).

If you use textmode per default, you at least need to mount the directory into which you will check out your configs in binary mode. Doing this is easy in Cygwin. You can see your mounted directories with mount and the respective commands with mount -m. The important flags are -t for text- and -b for binary mode.

As an example, let’s assume you want to mount User’s $HOME directory in binary mode:

mount -f -s -b "C:/cygwin/home/User" "/home/User"

Getting the window$ version of Vim to use your settings

I assume you still know how to retrieve the settings via git from the first part of this mini-series, so I’ll skip that as it works just the same way under Cygwin. Once you’re done, rename the file C:\Programs\Vim\_vimrc and create a new file with the same name and edit it:

set runtimepath+=C:\cygwin\home\User\.config\vim\.vim
set runtimepath+=C:\cygwin\home\User\.config\vim\.vim\after
source C:\cygwin\home\User\.config\vim\.vimrc

Replace User with your username under window$ and the next time you start the window$ version of Vim, it should use the settings imported with git.

Have fun!


  1. Malte Skoruppa says:

    Hey Timo,

    you might want to have a look at Portable Ubuntu:

    This will probably save you a lot of the troubles you’re having with Cywgin, and it’s much more comfortable too. Why, you’ll even have apt-get ;-) Just install Portable Ubuntu (and throw out Cygwin), and all your config files will be 100% compatible… I guess.
    (To be honest I never used Portable Ubuntu myself, but that’s only because I don’t have to use Windows on an everyday basis, like you do. If I did, I’d most certainly try it _before_ I put myself to all the Cygwin hassle. I saw Portable Ubuntu several times now and it looks fantastic!)

    Admittedly, it’s just a tiny bit more demanding on resources than Cygwin (though in my opinion, this is more than compensated by its ease of use and awesomeness!), so knowing you ol’ fanatic of lightweight programs, I guess you may stick with Cygwin all the same ;-) So on a related sidenote, you may also be interested in Cygwin Portable:
    This is a different idea: it’s good old Cygwin, but installed on a USB stick. So you can carry around all your favorite Linux programs for Windows with you (along with your git repository), and you only have to do the hacking (e.g. for vim) once, instead of being forced to do it anew for every Windows system you’ll ever want to use Cygwin and your configuration files in :)



  2. the_isz says:

    Wow, I have never heard of that project before. Neither did I know you are
    actively reading this blog. So you’re that one ;)

    However, I’ll surely give this a shot sometime, though I don’t think it’ll not
    suffer from the same issues as cygwin. As noted in the blog entry, Linux and
    window$ user different line endings (as you are certainly aware of).

    For the programs I’m writing, I must use the window$ line endings so that I
    conform to the code of my colleagues, which is why I’m using the window$ version
    of Vim. The unix tools I’m using – first and foremost git – need unix line
    endings. It’s a slippery rope I’m wandering on every day to make sure I don’t
    use the wrong endings.

    But I’ll try Portable Ubuntu nevertheless. Maybe the Ubuntu guys have thought of
    something the cygwin guys did not come up with.

  3. Malte Skoruppa says:

    Well, of course I read your blog actively. It’s a lot of fun! :) In fact I subscribed to the RSS feed, so I receive any entries you write by email.

    You’re probably right, if you used Portable Ubuntu with vim (the Linux version of vim you could install within Portable Ubuntu, I mean), you’d probably get the same problems with your line endings, even when saving them to a NTFS partition. The reason why I thought PU more attractive than Cygwin is just that it offers you all the features of a true Linux system, and not just a few ported apps (though there are many of those, I should admit). Also it’s much more straightforward and comfortable to use :)

    But now that I think about this CR/LF story, I actually don’t see much of a problem ;-) My first, spontaneous thought was to use the unix2dos utility, which has been around for a long time and does exactly what you want. But maybe you don’t want having to remember to run unix2dos on all your files each and every time you edited them. Though you could probably write a script that finds all Unix-style files in a directory, then runs unix2dos on each of them, and have this script being executed automatically each time before you commit something, this would also boil down to a lot of hacking…
    \But\, I thought, \vim is such a powerful editor it certainly is able to do this by itself.\ So although you know vim a lot better than me, I asked Google and it came up with this:
    So it looks like vim does this automatically; doesn’t it? When you edit a Windows-style file, vim should save it Windows-style. Or does the problem only occur when you create a new file? Even then, you can tell vim to save it Windows-style, and I would be surprised if you couldn’t configure vim in such a way that it does this by default.

    Anyway… my original thought was just that using a full-fledged Linux system with all available apps and everything you need within Windows (like, you could write bash scripts and cron jobs) would be nicer than just using some Linux tools that have been ported to Windows. Try it out if you like, I know you’ll be fine anyway ;-)


  4. the_isz says:

    I’ve got an active subscription!? This keeps getting better and better :D

    Actually, cygwin offers everything I could possibly want from a Linux
    environment. Recently, I even reinstalled it to make sure it doesn’t install an
    X server as I noticed I don’t actually need it. I also tried MinGW
    recently and even that – in spite of its horrible (read non-existant)
    installation routine – would have sufficed, hadn’t it been for the lack of

    I do know the unix2dos and dos2unix commands and even if I didn’t want to use
    them, I knew how to emulate their behaviour with tools such as tr and sed.

    You are right about Vim being able to chose the line endings automatically and I
    also know how to tell Vim to use endings different than the ones detected. But
    Vim isn’t really the problematic application in my case as there’s a native
    windows version of it anyway.

    The real problems arise with shell scripts and git. Shell scripts need Unix line
    endings, otherwise they get into real trouble because of the extra newline at
    the end of each line. Thus, it is not wise to convert these or the directories
    containing them to window$ file endings.
    Many other Unix tools, such as cat and sed, which output to to the console, tend
    to convert the files on which they work, which becomes very annoying when using
    them within scripts (which I do a lot). And if you tell cygwin to use window$
    line endings only, these tools get really confused, rendering them practically

    git is yet another big problem, as it destroys your repository after your first
    commit if its directory doesn’t use unix line endings. I know there is a MinGW
    port of git available, but this one only works on the window$ shell… a vicious

    Thus I decided for the combination of Vim’s window$ version and cygwin with unix
    line endings. That way, I only need to pay attention if I’m using shell scripts
    on files which are intended to have window$ line endings. And here I must get
    used to use unix2dos afterwards… just to be sure ;)

Leave a Reply

You must be logged in to post a comment.