Vim Tips Wiki
Tip 381 Printable Monobook Previous Next

created December 3, 2002 · complexity basic · author Luc Hermitte · version -

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

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.
  • 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

So, to come around this issue, here is a shell script that can be used to define aliases: More help is available on the script page

All you have to do is to drop it into one directory from your $PATH, and define into your .profile something like:

alias gvim=' "C:/Progra~1/Edition/vim/vim61/gvim.exe" -c'


  • under MsWindows 9x, I had to write the path to gvim.exe in the Windows short form
  • the '-c' is here to tell that: when calling Vim, the parameter following '-c' is not a path.
This enables us to write:
gvim -c '/^$/'

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. For example, ':sp /etc/pr<tab>' won't expand.


Just to announce the ver 2.2 of

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)

A light and faster script in some cases, though does not provide much options
--Siddhant, 25 Feb 2010

The new syntax to use it with gvim is:

alias gvim=' "C:/Progra~1/Edition/vim/vim61/gvim.exe"

Check ' --help | less' for help.

Note: This version requires cygUtils and more precisally realpath.exe --Luc Hermitte, December 5, 2002 10:35

> 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.

'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 conversion layer needs to be introduced if we want to use paths in such form.
--Luc Hermitte, February 6, 2003 5:13

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/ 2003-10-22 14:49:25.084774400 +0200
+++ /opt/bin/ 2003-10-22 14:55:04.392675200 +0200
@@ -254,6 +254,9 @@
+ elif [ `expr "$1" : "[a-z]*://.*"` -gt 0 ] ; then
+ # some netrw protocol like http://host or ftp://host : leave as is
+ ptransl="$1"
 # Convert pathname "$1" to absolute path (*nix form) and resolve
 # all the symbolic links

--Matthias.Morche October 22, 2003 6:00

Matthias patch has been taken into account. --Luc Hermitte 19:51, 5 June 2007 (UTC)

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

As far as I understand Cygwin, this can not work.
Backslashes have to be doubled or written within a pair of quotes.
--Luc Hermitte, February 26, 2004 15:17

It seems current version(1.42) of cygpath is not working properly when used with -wl alongside non existent filename.

$ cygpath -w /home/username/foo
$ cygpath -wl /home/username/foo
c:\cygwin\ho ??? sername\foo (??? is some random characters)

Please substitute 'cygpath -w' for 'cygpath -wl'; there are three instances. =)

AFAIK, this issue in cygpath hasn't been fixed yet
--Luc Hermitte 19:51, 5 June 2007 (UTC)

Option to "read text from stdin" doesn't work.

I'm using version 2.18 of the script and I've set up my gvim() bash function as follows:

function gvim() {
    if [ `expr "$*" : '.*tex\>'` -gt 0 ] ; then
        opt='--servername LATEX '
    fi "C:/Program Files (x86)/Vim/vim74/gvim.exe" --binary-opt=-c,--cmd,-T,-t,--servername,--remote-send,--remote-expr --cyg-verbose=1 --fork=1 --cmd "cd $(cygpath -w "$(pwd)")" $opt "$@"

And the command that I am trying to get working would be something like the following:

$ cat $somefile | gvim - # using the bash function defined above, not the executable.

Because it is not function as expected, I end up using the gvim.bat script distributed by vim:

$ cat $somefile | gvim.bat -

This works as expected, so I've assigned an alias just for this case

$ alias gv='gvim.bat -'

Any assistance with this issue would be greatly appreciated.

Thank you.