Vim Tips Wiki
No edit summary
 
m (Links to cyg-wrapper.sh updated)
Tags: Visual edit apiedit
 
(9 intermediate revisions by 6 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.
 
  +
}}
  +
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:
Note: I call a "native win32 application", any program that has not been specifically compiled to run on cygwin.
 
  +
*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: [https://github.com/LucHermitte/Bash-scripts/blob/master/cyg-wrapper.sh cyg-wrapper.sh]
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.
 
  +
More help is available on the [https://github.com/LucHermitte/Bash-scripts#cyg-wrappersh 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='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.
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:
 
   
  +
Last point, the win32 version of Vim can not expand paths expressed in the *nix way.
- express paths as *nix-like paths ; e.g. /etc/profile
 
  +
For example, ':sp /etc/pr<tab>' won't expand.
   
  +
==Comments==
- use paths that, as a matter of fact, are symbolic links.
 
  +
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:
So, to come around this issue, here is a shell script that can be used to define aliases:
 
  +
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.
http://hermitte.free.fr/cygwin/cyg-wrapper.sh
 
   
  +
Note: This version requires cygUtils and more precisally realpath.exe
[More help available on: http://hermitte.free.fr/cygwin&#35;Win32]
 
  +
--[[User:Luc Hermitte|Luc Hermitte]], December 5, 2002 10:35
 
 
 
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&lt;tab&gt;' won't expand.
 
 
 
}}
 
 
== Comments ==
 
I made a small mistake, I help page is:
 
http://hermitte.free.fr/cygwin/&#35;Win32
 
 
hermitte {at} free {dot} fr
 
, December 3, 2002 9:27
 
 
----
 
----
  +
> Last point, the win32 version of Vim can not expand paths expressed in the *nix way ;
I have just update cyg-wrapper.sh.
 
  +
> e.g. ':sp /etc/pr<tab>' won't expand.
Now, you will be able to:
 
  +
*{{help|'shellslash'}}
 
  +
:'shellslash' has almost nothing to do with that problem.
(*) Use absolute paths expressed in the windows form
 
  +
: On Cygwin, "/etc/something" refers in fact to "c:\Cygwin\etc\something" (assuming Cygwin has been installed into "c:\Cygwin").
&gt; gvim c:/bar/foo.txt
 
  +
: 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.
 
  +
:--[[User:Luc Hermitte|Luc Hermitte]], February 6, 2003 5:13
(*) Use multiple-level of indirections through symbolic links
 
  +
----
&gt; ln -s foo1 somepath
 
  +
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; ln -s foo2 foo1
 
  +
--- /DownLoad/vim/cyg-wrapper.sh 2003-10-22 14:49:25.084774400 +0200
&gt; ...
 
  +
+++ /opt/bin/cyg-wrapper.sh 2003-10-22 14:55:04.392675200 +0200
&gt; gvim foon
 
  +
@@ -254,6 +254,9 @@
 
  +
else
(*) Use symbolic links pointing to absolute paths expressed in the windows form
 
  +
ptransl="$1"
&gt; ln -s foo c:/bar/foo.txt
 
  +
fi
&gt; gvim foo
 
  +
+ elif [ `expr "$1" : "[a-z]*://.*"` -gt 0 ] ; then
 
  +
+ # some netrw protocol like http://host or ftp://host : leave as is
hermitte {at} free {dot} fr
 
  +
+ ptransl="$1"
, December 4, 2002 8:41
 
  +
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. --[[User:Luc Hermitte|Luc Hermitte]] 19:51, 5 June 2007 (UTC)
 
----
 
----
  +
This is just what I was looking for!
Just to announce the ver 2.2 of cyg-wrapper.sh.
 
   
  +
However, in the off chance I want to use win style path, e.g.,
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)
 
  +
gvim c:\Mydir\IOAPP.C
   
  +
gvim run but tries to open file c:\MydirIOAPP.C and says it's a new file.
The new syntax to use it with gvim is:
 
  +
It drops the 2nd backslash.
alias gvim='cyg-wrapper.sh "C:/Progra~1/Edition/vim/vim61/gvim.exe"
 
  +
Should this work or is it a bug in the cyg-wrapper.sh?
--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
 
   
  +
:As far as I understand Cygwin, this can not work.
hermitte {at} free {dot} fr
 
  +
:Backslashes have to be doubled or written within a pair of quotes.
, December 5, 2002 10:32
 
  +
:--[[User:Luc Hermitte|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.
Just to announce the ver 2.2 of cyg-wrapper.sh.
 
   
  +
$ cygpath -w /home/username/foo
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)
 
  +
c:\cygwin\home\username\foo
   
  +
$ cygpath -wl /home/username/foo
The new syntax to use it with gvim is:
 
  +
c:\cygwin\ho ??? sername\foo (??? is some random characters)
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'
 
   
  +
Please substitute 'cygpath -w' for 'cygpath -wl'; there are three instances. =)
Check 'cyg-wrapper.sh --help | less' for help.
 
 
Note: This version requires cygUtils and more precisally realpath.exe
 
   
  +
:AFAIK, this issue in cygpath hasn't been fixed yet
hermitte {at} free {dot} fr
 
  +
:--[[User:Luc Hermitte|Luc Hermitte]] 19:51, 5 June 2007 (UTC)
, December 5, 2002 10:35
 
 
----
 
----
  +
Option to "read text from stdin" doesn't work.
&gt; 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.
 
   
  +
I'm using version 2.18 of the cyg-wrapper.sh script and I've set up my gvim() bash function as follows:
[http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:'shellslash'}} :help 'shellslash']
 
   
  +
<pre>
'''Anonymous'''
 
  +
function gvim() {
, December 17, 2002 0:33
 
  +
opt=''
----
 
  +
if [ `expr "$*" : '.*tex\>'` -gt 0 ] ; then
&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.
 
  +
opt='--servername LATEX '
  +
fi
  +
cyg-wrapper.sh "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 "$@"
  +
}
  +
</pre>
   
  +
And the command that I am trying to get working would be something like the following:
&gt; [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:'shellslash'}} :help 'shellslash']
 
   
  +
<pre>
'shellslash' has almost nothing to do with that problem.
 
  +
$ cat $somefile | gvim - # using the bash function defined above, not the executable.
  +
</pre>
   
  +
Because it is not function as expected, I end up using the gvim.bat script distributed by vim:
On Cygwin, "/etc/something" refers in fact to "c:\Cygwin\etc\something" (assuming Cygwin has been installed into "c:\Cygwin").
 
   
  +
<pre>
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.
 
  +
$ cat $somefile | gvim.bat -
  +
</pre>
   
  +
This works as expected, so I've assigned an alias just for this case
hermitte {at} free {dot} fr
 
, 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:
 
   
  +
<pre>
--- /DownLoad/vim/cyg-wrapper.sh 2003-10-22 14:49:25.084774400 +0200
 
  +
$ alias gv='gvim.bat -'
+++ /opt/bin/cyg-wrapper.sh 2003-10-22 14:55:04.392675200 +0200
 
  +
</pre>
--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
 
   
  +
Any assistance with this issue would be greatly appreciated.
Matthias.Morche--AT--szm.de
 
, October 22, 2003 6:00
 
----
 
This is just what I was looking for!
 
   
  +
Thank you.
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?
 
 
gene.smith &lt;&lt;&lt;at&gt;&gt;&gt; sea dot siemens dot com
 
, February 25, 2004 8:24
 
----
 
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.
 
 
$ 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. =)
 
   
  +
--Tavish
bhkim {at} mit
 
, October 26, 2006 17:40
 
 
----
 
----
<!-- parsed by vimtips.py in 0.532776 seconds-->
 

Latest revision as of 10:51, 28 May 2015

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: cyg-wrapper.sh 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='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)

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

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

function gvim() {
    opt=''
    if [ `expr "$*" : '.*tex\>'` -gt 0 ] ; then
        opt='--servername LATEX '
    fi
    cyg-wrapper.sh "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.

--Tavish