Using Vim under Cygwin

Cygwin is a marvelous idea: run a Linux-like shell under Windows. It allows me to run Python, CVS, Perl… almost everything I use under Linux, under Windows. Well, it doesn’t quite work as well, but for small things, it does the job.

One thing that has annoyed me is their implementation of vim. The keyboard support is bad. In my .inputrc, I have these lines

# enable 8-bits characters ...
set meta-flag on
set convert-meta off
set output-meta on

They seem to clash with vim in a bad way. Ah! But you can also install a version of vim running directly on top of windows. If you do this, then you can use this other version instead of the one that comes with cygwin.

All I had to do was to create this little script:

 "/cygdrive/c/Program Files/Vim/vim63/vim.exe" `cygpath -w $1`

The trick here is that you need to convert Linux-like paths (like /tmp) into Windows path (C:…). My little script is bad in many ways, but it will work if you call vim with only a file name as an argument.

My solution does fail in some nasty ways. For example, when I do a CVS commit, I can’t enter my comment. Bad.

See also my post Grep is just not for matching lines anymore.

Subscribe to this blog
in a reader
or by Email.

12 thoughts on “Using Vim under Cygwin”

  1. -m message

    Use message as log information, instead of invoking an editor.

    Available with the following commands: add, commit and import.

    From cvs man page.

  2. Thanks. Indeed a good alternative.

    I knew about the “-m” command, but also, under windows, one can use Tortoise CVS, you then have a nice GUI to take care of all your CVS trouble. But I remain a command line freak. So I should get in the habit of using -m, it is probably faster in the long run anyhow.

  3. cat ~/.bashrc

    vi(){ # windows.
    vifile=${@:-$vifile}; # use last file or argv
    vifile=$(cygpath -m $@) # dos paths
    c:/bin32/gvim $vifile &
    }

    I too just started using cygwin and tortoise-cvs.

  4. Hello.

    I do not really like to post such plain advertizes, but I think the script I’m maintening, cyg-wrapper.sh, could solve both your problems. (If I understand how the blog works, just click on my name to access to the script).

    Regarding Vim, look at the example given on the web page. Regarding cvs, declare -m as a binary-argument. BTW, Vim plugin, cvsmenu, is quite addictive — though I have used it only on Solaris.

    NB: As cyg-wrapper is just a bash script, it may take some time when to many filenames need to be converted.

    HTH.

  5. The script as given above will only edit one file. What if you want to edit several files? What if you want to edit several files and start all open in their own frame? If you add the “-o” switch cypath will take it as a option so it probably produce an error and it won’t get passed to Vim.

    Here’s the original script:

    “/cygdrive/c/Program Files/Vim/vim63/vim.exe” `cygpath -w $1`

    Here’s a more useful variation (assuming the Bash shell):

    “/cygdrive…/vim.exe” $(cygpath -w — $*) &

    Cygpath ignores options after the “–“.

  6. I experienced several issues using vim ( ex – pressing “i” didn’t put it into INSERT mode ), i created a blank file ~/.vimrc and everything worked great.

  7. Greg is right
    touch.exe ~/.vimrc
    and you don’t need to install the other vim, cygwin vim suddenly starts working just fine!!

  8. creating a blank .vimrc file in ~/ to make cygwin-installed vim or gvim behave correctly, is the most brilliant idea I’ve seen so far in 2011.

  9. so I took it to the next level. I went to my most-used linux shell, grabbed my .vimrc file, and scp’d it into my cygwin ~/ folder. Now I am in business!

  10. I am not able to run gvim from cygwin. When I try to open a new file with :

    gvim filename gvim opens and displays error as :

    Error detected while processing command line
    E492: Not editor command: C:\cygwin\home\chandan\l
    Press enter or type command to continue
    More problematic is that I can’t open existing file in the path

    >which gvim shows /usr/bin/gvim

    I have put alias gvim=/cygdrive/c/Program\Files\(x86\)/Vim/vim73/gvim.exe still

    Thanks,

    Chandan

Leave a Reply

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