sponsor Vim development Vim logo Vim Book Ad

basic Tip #381: Running the win32-version of Vim from cygwin

 tip karma   Rating 33/15, Viewed by 2352 

created:   December 3, 2002 8:40      complexity:   basic
author:   Luc Hermitte      as of Vim:   5.7

This tip does not only concern Vim, but any native win32 application (NWA) we may want to run from cygwin.

Note: I call a "native win32 application", any program that has not been specifically compiled to run on cygwin.
Typical examples are internet explorer, yap, acrobat reader, ... and of course the win32 version of Vim available on this site or on http://cream.sourceforge.net.

The problem with running NWAs from cygwin comes from the fact that paths in cygwin can be expressed in ways that NWAs can't understand. Indeed from cygwin, we can also:
- express paths as *nix-like paths ; e.g.  /etc/profile
- use paths that, as a matter of fact, are symbolic links.

So, to come around this issue, here is a shell script that can be used to define aliases:
    http://hermitte.free.fr/cygwin/cyg-wrapper.sh
[More help available on: http://hermitte.free.fr/cygwin#Win32]

All you have to do is to drop it into one directory from your $PATH, and define into your .profile something like:
    alias gvim='cyg-wrapper.sh "C:/Progra~1/Edition/vim/vim61/gvim.exe" -c'

Notes:
- under MsWindows 9x, I had to writte the path to gvim.exe in the windows short form
- the '-c' is here to tell cyg-wrapper.sh that: when calling VIM, the parameter following '-c' is not a path.
  This enables to write:
         gvim -c '/^$/' foo.xxx


Regarding the use of *nix-like paths from win32-VIM, check Johannes Zellner's plugin (cygwin.vim) that will convert *nix paths into MsWindows paths on file-opening -- there are different autocommand to add, but it will give you the main idea.
Last point, the win32 version of Vim can not expand paths expressed in the *nix way ;
e.g. ':sp /etc/pr<tab>' won't expand.

 rate this tip  Life Changing Helpful Unfulfilling 

<<Using gvim as frontend for dbx | Search and replace in all open buffers >>

Additional Notes

hermitte {at} free {dot} fr, December 3, 2002 9:27
I made a small mistake, I help page is:
    http://hermitte.free.fr/cygwin/#Win32
hermitte {at} free {dot} fr, December 4, 2002 8:41
I have just update cyg-wrapper.sh.
Now, you will be able to:

(*) Use absolute paths expressed in the windows form    
>    gvim c:/bar/foo.txt

(*) Use multiple-level of indirections through symbolic links
>    ln -s foo1 somepath
>    ln -s foo2 foo1
>    ...
>    gvim foon

(*)  Use symbolic links pointing to absolute paths expressed in the windows form
>    ln -s foo c:/bar/foo.txt
>    gvim foo
hermitte {at} free {dot} fr, December 5, 2002 10:32
Just to announce the ver 2.2 of cyg-wrapper.sh.

It is quicker than the version 1.x, the options are correctly supported and we can ask for a non forking program to fork (thanks to Jonathon M. Merz)

The new syntax to use it with gvim is:
  alias gvim='cyg-wrapper.sh "C:/Progra~1/Edition/vim/vim61/gvim.exe"
--binary-opt=-c,--cmd,-T,-t,--servername,--remote-send,--remote-expr
--fork=1'

Check 'cyg-wrapper.sh --help | less' for help.

Note: This version requires cygUtils and more precisally realpath.exe
hermitte {at} free {dot} fr, December 5, 2002 10:35
Just to announce the ver 2.2 of cyg-wrapper.sh.

It is quicker than the version 1.x, the options are correctly supported and we can ask for a non forking program to fork (thanks to Jonathon M. Merz)

The new syntax to use it with gvim is:
  alias gvim='cyg-wrapper.sh "C:/Progra~1/Edition/vim/vim61/gvim.exe"
--binary-opt=-c,--cmd,-T,-t,--servername,--remote-send,--remote-expr
--fork=1'

Check 'cyg-wrapper.sh --help | less' for help.

Note: This version requires cygUtils and more precisally realpath.exe
Anonymous, December 17, 2002 0:33
> Last point, the win32 version of Vim can not expand paths expressed in the *nix way ;
> e.g. ':sp /etc/pr<tab>' won't expand.

:help 'shellslash'
hermitte {at} free {dot} fr, February 6, 2003 5:13
> > Last point, the win32 version of Vim can not expand paths expressed in the *nix > > way ; e.g. ':sp /etc/pr<tab>' won't expand.

> :help 'shellslash'

'shellslash' has almost nothing to do with that problem.

On Cygwin, "/etc/something" refers in fact to "c:\Cygwin\etc\something" (assuming Cygwin has been installed into "c:\Cygwin").

Vim is not able to translate *nix paths into plain MsWindows paths -- a convertion layer needs to be introduced if we want to use paths in such form.
[email protected], October 22, 2003 6:00
I've detected a tiny flaw: if You want to use netrw (eg. gvim scp://somehost/somefile) from the commandline You loose. Here's the patch to recognise url syntax and handle it properly:

--- /DownLoad/vim/cyg-wrapper.sh        2003-10-22 14:49:25.084774400 +0200
+++ /opt/bin/cyg-wrapper.sh     2003-10-22 14:55:04.392675200 +0200
@@ -254,6 +254,9 @@
        else
            ptransl="$1"
        fi
+    elif [ `expr "$1" : "[a-z]*://.*"` -gt 0 ] ; then
+       # some netrw protocol like http://host or ftp://host : leave as is
+       ptransl="$1"
     else
        # Convert pathname "$1" to absolute path (*nix form) and resolve
        # all the symbolic links
gene.smith <<<at>>> sea   dot  siemens dot com, February 25, 2004 8:24
This is just what I was looking for!

However, in the off chance I want to use win style path, e.g.,
gvim c:\Mydir\IOAPP.C

gvim run but tries to open file c:\MydirIOAPP.C and says it's a new file.
It drops the 2nd backslash.
Should this work or is it a bug in the cyg-wrapper.sh?
hermitte {at} free {dot} fr, February 26, 2004 15:17
As far as I understand Cygwin, this can not work.
Backslashes have to be doubled or written within a pair of quotes.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo