Vim Tips Wiki
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{TipImported
{{review}}
 
{{Tip
 
 
|id=381
 
|id=381
  +
|previous=380
|title=Running the win32-version of Vim from cygwin
 
  +
|next=382
|created=December 3, 2002 8:40
+
|created=December 3, 2002
 
|complexity=basic
 
|complexity=basic
|author=Luc Hermitte
+
|author=[[User:Luc Hermitte|Luc Hermitte]]
|version=5.7
+
|version=-
 
|rating=46/19
 
|rating=46/19
  +
|category1=Cygwin
|text=
 
  +
|category2=
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.
 
 
 
 
}}
 
}}
 
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.
== Comments ==
 
I made a small mistake, I help page is:
 
http://hermitte.free.fr/cygwin/#Win32
 
   
 
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.
hermitte {at} free {dot} fr
 
, December 3, 2002 9:27
 
----
 
I have just update cyg-wrapper.sh.
 
Now, you will be able to:
 
   
 
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:
(*) Use absolute paths expressed in the windows form
 
 
*Express paths as *nix-like paths ; e.g. /etc/profile
> gvim c:/bar/foo.txt
 
 
*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: http://hermitte.free.fr/cygwin/cyg-wrapper.sh
(*) Use multiple-level of indirections through symbolic links
 
 
More help is available on: http://hermitte.free.fr/cygwin/#Win32
> ln -s foo1 somepath
 
> ln -s foo2 foo1
 
> ...
 
> gvim foon
 
   
 
All you have to do is to drop it into one directory from your $PATH, and define into your .profile something like:
(*) Use symbolic links pointing to absolute paths expressed in the windows form
 
 
alias gvim='cyg-wrapper.sh "C:/Progra~1/Edition/vim/vim61/gvim.exe" -c'
> ln -s foo c:/bar/foo.txt
 
> gvim foo
 
   
 
Notes:
hermitte {at} free {dot} fr
 
 
*under MsWindows 9x, I had to write the path to gvim.exe in the Windows short form
, December 4, 2002 8:41
 
 
*the '-c' is here to tell cyg-wrapper.sh that: when calling Vim, the parameter following '-c' is not a path.
----
 
 
:This enables us to write:
Just to announce the ver 2.2 of cyg-wrapper.sh.
 
 
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.
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)
 
   
 
Last point, the win32 version of Vim can not expand paths expressed in the *nix way.
The new syntax to use it with gvim is:
 
 
For example, ':sp /etc/pr<tab>' won't expand.
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'
 
   
 
==Comments==
Check 'cyg-wrapper.sh --help | less' for help.
 
 
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)
Note: This version requires cygUtils and more precisally realpath.exe
 
   
  +
:A light and faster script in some cases, though does not provide much options
hermitte {at} free {dot} fr
 
  +
:http://vim.wikia.com/wiki/Use_cygwin_shell
, December 5, 2002 10:32
 
  +
:--Siddhant, 25 Feb 2010
----
 
Just to announce the ver 2.2 of cyg-wrapper.sh.
 
   
 
The new syntax to use it with gvim is:
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)
 
 
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.
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
 
Note: This version requires cygUtils and more precisally realpath.exe
  +
--[[User:Luc Hermitte|Luc Hermitte]], December 5, 2002 10:35
 
hermitte {at} free {dot} fr
 
, December 5, 2002 10:35
 
 
----
 
----
&gt; Last point, the win32 version of Vim can not expand paths expressed in the *nix way ;
+
> Last point, the win32 version of Vim can not expand paths expressed in the *nix way ;
&gt; e.g. ':sp /etc/pr&lt;tab&gt;' won't expand.
+
> e.g. ':sp /etc/pr<tab>' won't expand.
  +
*{{help|'shellslash'}}
 
 
:'shellslash' has almost nothing to do with that problem.
[http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:'shellslash'}} :help 'shellslash']
 
 
: 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.
'''Anonymous'''
 
  +
:--[[User:Luc Hermitte|Luc Hermitte]], February 6, 2003 5:13
, December 17, 2002 0:33
 
 
----
 
----
 
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:
&gt; &gt; Last point, the win32 version of Vim can not expand paths expressed in the *nix &gt; &gt; way ; e.g. ':sp /etc/pr&lt;tab&gt;' won't expand.
 
 
--- /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
&gt; [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:'shellslash'}} :help 'shellslash']
 
  +
@@ -254,6 +254,9 @@
 
  +
else
'shellslash' has almost nothing to do with that problem.
 
 
ptransl="$1"
 
  +
fi
On Cygwin, "/etc/something" refers in fact to "c:\Cygwin\etc\something" (assuming Cygwin has been installed into "c:\Cygwin").
 
 
+ elif [ `expr "$1" : "[a-z]*://.*"` -gt 0 ] ; then
 
 
+ # some netrw protocol like http://host or ftp://host : leave as is
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.
 
 
+ ptransl="$1"
 
  +
else
hermitte {at} free {dot} fr
 
 
# Convert pathname "$1" to absolute path (*nix form) and resolve
, February 6, 2003 5:13
 
 
# all the symbolic links
 
--Matthias.Morche October 22, 2003 6:00
  +
:Matthias patch has been taken into account. --[[User:Luc Hermitte|Luc Hermitte]] 19:51, 5 June 2007 (UTC)
 
----
 
----
 
This is just what I was looking for!
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:
 
   
 
However, in the off chance I want to use win style path, e.g.,
--- /DownLoad/vim/cyg-wrapper.sh 2003-10-22 14:49:25.084774400 +0200
 
 
gvim c:\Mydir\IOAPP.C
+++ /opt/bin/cyg-wrapper.sh 2003-10-22 14:55:04.392675200 +0200
 
--AT----AT-- -254,6 +254,9 --AT----AT--
 
else
 
ptransl="$1"
 
fi
 
+ elif [ `expr "$1" : "[a-z]*://.*"` -gt 0 ] ; then
 
+ &#35; some netrw protocol like http://host or ftp://host : leave as is
 
+ ptransl="$1"
 
else
 
&#35; Convert pathname "$1" to absolute path (*nix form) and resolve
 
&#35; all the symbolic links
 
   
 
gvim run but tries to open file c:\MydirIOAPP.C and says it's a new file.
Matthias.Morche--AT--szm.de
 
 
It drops the 2nd backslash.
, October 22, 2003 6:00
 
----
 
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?
 
Should this work or is it a bug in the cyg-wrapper.sh?
   
 
:As far as I understand Cygwin, this can not work.
gene.smith &lt;&lt;&lt;at&gt;&gt;&gt; sea dot siemens dot com
 
 
:Backslashes have to be doubled or written within a pair of quotes.
, February 25, 2004 8:24
 
  +
:--[[User:Luc Hermitte|Luc Hermitte]], 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.
 
 
hermitte {at} free {dot} fr
 
, 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.
+
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 -w /home/username/foo
c:\cygwin\home\username\foo
+
c:\cygwin\home\username\foo
   
$ cygpath -wl /home/username/foo
+
$ cygpath -wl /home/username/foo
c:\cygwin\ho ??? sername\foo (??? is some random characters)
+
c:\cygwin\ho ??? sername\foo (??? is some random characters)
   
 
Please substitute 'cygpath -w' for 'cygpath -wl'; there are three instances. =)
 
Please substitute 'cygpath -w' for 'cygpath -wl'; there are three instances. =)
   
  +
:AFAIK, this issue in cygpath hasn't been fixed yet
bhkim {at} mit
 
  +
:--[[User:Luc Hermitte|Luc Hermitte]] 19:51, 5 June 2007 (UTC)
, October 26, 2006 17:40
 
 
----
 
----
<!-- parsed by vimtips.py in 0.532776 seconds-->
 

Revision as of 04:18, 26 February 2010

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 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.
  • 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: http://hermitte.free.fr/cygwin/cyg-wrapper.sh More help is 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 write 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 us 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. For example, ':sp /etc/pr<tab>' won't expand.

Comments

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)

A light and faster script in some cases, though does not provide much options
http://vim.wikia.com/wiki/Use_cygwin_shell
--Siddhant, 25 Feb 2010

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

--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 cyg-wrapper.sh?

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
c:\cygwin\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)