Vim Tips Wiki
m (Added to Cygwin Category)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=814
 
|id=814
  +
|previous=813
|title=Use cygwin shell
 
  +
|next=816
|created=November 3, 2004 7:48
+
|created=November 3, 2004
 
|complexity=intermediate
 
|complexity=intermediate
|author=Jamie Sanderson (jamie at sanderson dot ca)
+
|author=Jamie Sanderson
 
|version=5.7
 
|version=5.7
 
|rating=31/13
 
|rating=31/13
 
}}
|text=
 
By default, Vim on Windows uses the "Command Prompt" as its shell. If you have Cygwin installed (http://www.cygwin.com) you may want to use one of its shells instead, such as bash. This also makes all of the programs installed under Cygwin available for text processing.
+
By default, Vim on Windows uses the "Command Prompt" as its shell. If you have Cygwin installed (http://www.cygwin.com) you may want to use one of its shells instead, such as bash. This also makes all of the programs installed under Cygwin available for text processing.
   
The following settings may be included in a startup script to use bash as your shell. I have these commands in my _gvimrc file in the installation directory.
+
The following settings may be included in a startup script to use bash as your shell. I have these commands in my gvimrc file in the installation directory.
set shell=C:/cygwin/bin/bash
 
set shellcmdflag=--login\ -c
 
set shellxquote=\"
 
   
  +
<pre>
I had problems with parts of the /etc/profile not being executed, but I didn't want to add -i (interactive) to the shellcmdflag because this caused the shell to always open in my home directory. I prefer that it opens in the directory containing the file being edited. However, without that part of /etc/profile running, the path wasn't set up properly. To get around this, I added the following line to /etc/profile:
 
 
set shell=C:/cygwin/bin/bash
RANPROFILE="TRUE"
 
 
set shellcmdflag=--login\ -c
 
set shellxquote=\"
  +
</pre>
   
 
I had problems with parts of the /etc/profile not being executed, but I didn't want to add -i (interactive) to the shellcmdflag because this caused the shell to always open in my home directory. I prefer that it opens in the directory containing the file being edited. However, without that part of /etc/profile running, the path wasn't set up properly. To get around this, I added the following line to /etc/profile:
I added this to my .bashrc:
 
if [ -z "$RANPROFILE" ]; then
 
PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
 
fi
 
   
  +
<pre>
Newer versions of the /etc/profile installed with Cygwin may behave differently.
 
 
RANPROFILE="TRUE"
}}
 
  +
</pre>
   
 
I added this to my .bashrc:
== Comments ==
 
vimdiff (in gvim) doesn't seem to work with cygwin as default shell
 
   
  +
<pre>
'''Anonymous'''
 
 
if [ -z "$RANPROFILE" ]; then
, November 16, 2004 5:52
 
 
PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
----
 
  +
fi
I can't even get vim to open up a file properly in cygwin anytime I'm not in the actual directory of the file.
 
  +
</pre>
   
 
Newer versions of the /etc/profile installed with Cygwin may behave differently.
Any help?
 
   
 
==Comments==
Thanks.
 
 
vimdiff (in gvim) doesn't seem to work with cygwin as default shell
   
'''Anonymous'''
 
, November 16, 2004 17:01
 
 
----
 
----
Goto cygwin setup, and install editors-&gt;vim,
+
Go to cygwin setup, and install editors-&gt;vim,
  +
it understands /cygdrive/c/ syntax, the regular
+
It understands /cygdrive/c/ syntax, the regular Vim does not.
vim does not.
 
   
Mala Sinha
 
, April 8, 2005 23:03
 
 
----
 
----
I use Cygwin along with the Windows version gVim. It's true that this version of gVim doesn't understand the "cygdrive" syntax, so you have to use the cygpath command to convert your paths before it will work.
+
I use Cygwin along with the Windows version gVim. It's true that this version of gVim doesn't understand the "cygdrive" syntax, so you have to use the cygpath command to convert your paths before it will work.
   
Here is a bash script I wrote that translates the paths and launches gVim as a background process. I added an alias to my .bash_profile so I generally forget it's there. There are probably better ways to do this, but it works for me:
+
Here is a bash script I wrote that translates the paths and launches gvim as a background process. I added an alias to my .bash_profile so I generally forget it's there. There are probably better ways to do this, but it works for me:
   
  +
<pre>
CMD="gvim"
+
CMD="gvim"
while [ -n "$1" ]; do
 
if [ -n "`echo $1 | grep '^-'`" ]; then
+
while [ -n "$1" ]; do
  +
if [ -n "`echo $1 | grep '^-'`" ]; then
ARG=$1
 
else
+
ARG=$1
  +
else
ARG=`cygpath --absolute --windows "$1"`
+
ARG=`cygpath --absolute --windows "$1"`
fi
 
 
fi
&#35; Escape spaces in arg
+
# Escape spaces in arg
ARG=`echo $ARG | sed -e 's/\\\\/\\\\\\\\/g' -e 's/ /\\\\ /g'`
+
ARG=`echo $ARG | sed -e 's/\\\\/\\\\\\\\/g' -e 's/ /\\\\ /g'`
CMD="$CMD $ARG"
+
CMD="$CMD $ARG"
shift;
+
shift;
done
+
done
bash -c "$CMD" &amp;
+
bash -c "$CMD" &amp;
  +
</pre>
   
'''Anonymous'''
 
, April 19, 2005 12:26
 
 
----
 
----
<!-- parsed by vimtips.py in 0.498016 seconds-->
 
 
[[Category:Cygwin]]
 
[[Category:Cygwin]]

Revision as of 00:56, 25 November 2007

Tip 814 Printable Monobook Previous Next

created November 3, 2004 · complexity intermediate · author Jamie Sanderson · version 5.7


By default, Vim on Windows uses the "Command Prompt" as its shell. If you have Cygwin installed (http://www.cygwin.com) you may want to use one of its shells instead, such as bash. This also makes all of the programs installed under Cygwin available for text processing.

The following settings may be included in a startup script to use bash as your shell. I have these commands in my gvimrc file in the installation directory.

set shell=C:/cygwin/bin/bash
set shellcmdflag=--login\ -c
set shellxquote=\"

I had problems with parts of the /etc/profile not being executed, but I didn't want to add -i (interactive) to the shellcmdflag because this caused the shell to always open in my home directory. I prefer that it opens in the directory containing the file being edited. However, without that part of /etc/profile running, the path wasn't set up properly. To get around this, I added the following line to /etc/profile:

RANPROFILE="TRUE"

I added this to my .bashrc:

if [ -z "$RANPROFILE" ]; then
  PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
fi

Newer versions of the /etc/profile installed with Cygwin may behave differently.

Comments

vimdiff (in gvim) doesn't seem to work with cygwin as default shell


Go to cygwin setup, and install editors->vim,

It understands /cygdrive/c/ syntax, the regular Vim does not.


I use Cygwin along with the Windows version gVim. It's true that this version of gVim doesn't understand the "cygdrive" syntax, so you have to use the cygpath command to convert your paths before it will work.

Here is a bash script I wrote that translates the paths and launches gvim as a background process. I added an alias to my .bash_profile so I generally forget it's there. There are probably better ways to do this, but it works for me:

CMD="gvim"
while [ -n "$1" ]; do
 if [ -n "`echo $1 | grep '^-'`" ]; then
  ARG=$1
 else
  ARG=`cygpath --absolute --windows "$1"`
 fi
 # Escape spaces in arg
 ARG=`echo $ARG | sed -e 's/\\\\/\\\\\\\\/g' -e 's/ /\\\\ /g'`
 CMD="$CMD $ARG"
 shift;
done
bash -c "$CMD" &