Getting to know Cygwin and Windows

Since I’m forced against my will to use Windows at my new job, I’ve quickly started using Cygwin. I haven’t used Windows in about 6 years, and I’m very use to using the command line. The folks at work actually use the windows command line, which I of course refuse to do.

I always knew about Cygwin but never actually needed to use it. It’s… well ok. It’s a good emulation of a linux terminal, however there were several things missing:

  1. tabs
  2. (g)vim didn’t work
  3. opening a new tab put me back into my home directory… errr!
  4. vim and the tweaks I use won’t save because swap files can’t be saved

Here’s how a I fixed all the following. 🙂

Tabs and extras

For now, I’m using Console 2. Console 2 allows you to run several different terminals within tabs in the app. It works, well enough, but I still am having problem with the window being the correct size. Sounds like mitty might take care of weird window size problems and scrolling issues; but I haven’t tried it out yet.


gvim didn’t work right out of the box, neither did vim for some reason so I ended up putting this in my .bashrc file:

alias vim='/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/vim.exe'
alias gvim='/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe'

open new tab from last directory

One feature I never realized I took for granted, from the Ubuntu terminal is opening a new tab and automatically being in the last directory you were in. My hack to make this work was the following:

First I like to record ever command I run, I find this helpful for that (very) occasional time you need to see what command you ran months ago. In this command, I’m also tracking the last directory I was in.

case "$TERM" in
    PROMPT_COMMAND='echo `date +"%b %e %Y %H:%M:%S"` $?  \"`history 1|cut -c7-`\" in `pwd` >> ~/_audit; echo `pwd` > ~/_dir_history'

Notice the last bit:

echo `pwd` > ~/_dir_history'

That’s where I write to a file in my home directory.

Then in my .bashrc file I cd to that directory:

cd "`tail -1 ~/_dir_history`"

getting vim to work and dealing with e303 unable to open swap file for

Finally, the pesky problems with vim opening up. By default the $TEMP location where vim wants to write swap files to was c:\cygwin\tmp. This didn’t work for some reason. (permission problems?) If you want to know where this directory is point to, open vim and run:

echo $TEMP

To solve this, in my _vimrc file (windows can’t use “.vimrc” so the windows version of vim uses _ instead of .) I had point to a different location for the temp directory, so I added this:

set directory=c:\tmp

I made a new directory in my c:\ called tmp and just used that directory. No more errors. BTW… if you want to see errors in vim this command is extremely handy:


All in all, my setup is now a lot closer to what I’m use to with Ubuntu. I still really really hate using Windows, but at least I have a command line, BASH, and node.js runs in windows. 🙂


The “clear” command doesn’t work in cygwin so I had to add this alias to my .bashrc:

alias clear='echo -n ^[[2J'

I used vim to add ^[. To type the control character and the rest type the following into vim: Ctrl+v, Esc, [, 2, J

Leave a Reply

Your email address will not be published. Required fields are marked *