Cannot use vimdiff when started from cygwin

1,250 views
Skip to first unread message

skeept

unread,
Jul 11, 2012, 11:01:44 AM7/11/12
to vim...@googlegroups.com
Hi,

I am trying to start vimdiff from a cygwin shell but it is not working properly.

I start it with
gvimdiff.bat file1 file2

and the error messages I get is:
E810: Cannot read or write temp files
E97: Cannot create diffs

I tried setting different values for the TMP variable in _vimrc, something like
let $TMP="C:/tmp"

but this isn't doing any difference.

vimdiff works fine if it is started from a cmd shell.

I tried
:!diff -v
in gvim started from the cmd and from cygwin.

From cmd I get:
c:\windwos\system32\cmd.exe /c (diff -v)
diff - GNU diffutils version 2.7

From cygwin I get:
/bin/bash -c "diff -v"
The system cannot find the path specified.
sheell returned 1


Any idea how to make diff work on gvimdiff.bat started from cygwin bash shell?

Thanks.

Christian Brabandt

unread,
Jul 11, 2012, 11:18:41 AM7/11/12
to vim...@googlegroups.com
Generally, mixing Cygwin and non-Cygwin programs always causes trouble.

In your case, I suspect, Vim fails to create temporary files for the diff.
So please show us the output of :echo tempname() from Cygwin vim and
gvim.

Is this directory accessible from gvim/Cygwin vim (consider Windows can't
cope with paths starting with / and Cygwin Vim can't handle Windows paths)?

regards,
Christian

skeept

unread,
Jul 11, 2012, 11:31:32 AM7/11/12
to vim...@googlegroups.com

> Generally, mixing Cygwin and non-Cygwin programs always causes trouble.
>
> In your case, I suspect, Vim fails to create temporary files for the diff.
> So please show us the output of :echo tempname() from Cygwin vim and
> gvim.
>
> Is this directory accessible from gvim/Cygwin vim (consider Windows can't
> cope with paths starting with / and Cygwin Vim can't handle Windows paths)?
>
> regards,
> Christian

Hi Christian,

the output for echo tempname() in gvim/windows is:
c:\htemp\tmp\VIBFED5.tmp

while the output for gvim/windows started from cygwin is:
c:/htemp/tmp/VIA693A.tmp

I use
if has("win32")
let $TMP = 'c:\\htemp\\tmp'
endif

to set the name of the variable but when started from cygwin it ends up with the separators in the oposite direction /.

Is it possible to set it in such a way that it would work?

Thanks!


Ben Fritz

unread,
Jul 11, 2012, 5:49:22 PM7/11/12
to vim...@googlegroups.com
On Wednesday, July 11, 2012 10:31:32 AM UTC-5, skeept wrote:
> > Generally, mixing Cygwin and non-Cygwin programs always causes trouble.
> >
> > In your case, I suspect, Vim fails to create temporary files for the diff.
> > So please show us the output of :echo tempname() from Cygwin vim and
> > gvim.
> >
> > Is this directory accessible from gvim/Cygwin vim (consider Windows can't
> > cope with paths starting with / and Cygwin Vim can't handle Windows paths)?
> >
> > regards,
> > Christian

>
> Hi Christian,
>
> the output for echo tempname() in gvim/windows is:
> c:\htemp\tmp\VIBFED5.tmp
>
> while the output for gvim/windows started from cygwin is:
> c:/htemp/tmp/VIA693A.tmp
>
> I use
> if has("win32")
> let $TMP = 'c:\\htemp\\tmp'

> endif
>
> to set the name of the variable but when started from cygwin it ends up with the separators in the oposite direction /.
>
> Is it possible to set it in such a way that it would work?
>
> Thanks!

Forward vs. backward slashes shouldn't matter, most Windows apps can handle both, cygwin apps can definitely handle forward slash, and a native Windows Vim can handle both.

Are you trying to access "c:/htemp/tmp" from a cygwin Vim, rather than a native Windows Vim? I don't use cygwin much (and never use Vim in cygwin) but apps I do use in cygwin don't understand C:/ paths, they use /cygdrive/c.

You said you were launching from cygwin with "gvimdiff.bat", is this actually true? Again, I don't use cygwin very often, but I know .bat files are scripts for the Windows cmd.exe shell, not for the cygwin shell, which uses bash or another unix shell. But maybe there is special handling built in to let it run cmd.exe scripts.

Ben Fritz

unread,
Jul 11, 2012, 11:20:03 PM7/11/12
to vim...@googlegroups.com
Is it possible for you to turn off the HTML formatting in whatever client you're using? It isn't translating properly on the Google Groups interface. I don't know what it looks like in an email.

On Wednesday, July 11, 2012 5:50:34 PM UTC-5, xxx wrote:
>
> I am in cygwin and trying to use windows native gvim (I don't even have gvim in cygwin, just vim). I am using gvimdiff.bat to launch gvim with the files.

OK, so I'm going to assume that somehow cygwin knows how to run *.bat files.

> Like I said before the problem would be around the fact that any shell command started from the gvim instance launched from cygwin gives the error
> /bin/bash -c "diff -v"
> The system cannot find the path specified.
> sheell returned 1
>
> which means it is trying to use the bash to run these commands when it maybe should run cmd, but I don't know how to fix this.

My guess:

You started a native-windows Vim from a cygwin shell. So Vim thinks the shell is whatever cygwin has it set to. However, once the native Vim is running outside of the cygwin environment, none of the cygwin paths are valid anymore. Vim doesn't know how to interpret /cygpath/c or /bin/bash or any of that. Native Windows Vim speaks native Windows file paths.

You MIGHT be able to fix this by setting the 'shell' option, and possibly also 'shellquote', 'shellxquote', and optionally 'noshellslash'. But I'm not sure. Your best bet would be not to call native Windows applications from cygwin.

You might also be able to set 'diffexpr' to a function which will select the correct diff, and also translate the paths passed in by cygwin.

skeept

unread,
Jul 12, 2012, 9:28:52 AM7/12/12
to vim...@googlegroups.com
> is it possible for you to turn off the HTML formatting in whatever client you're using? It isn't translating properly on the Google Groups interface. I don't know what it looks like in an email.

Sorry about that, I am just using the page in google groups to write the message, google groups is doing that by itself.

> You started a native-windows Vim from a cygwin shell. So Vim thinks the shell is whatever cygwin has it set to. However, once the native Vim is running outside of the cygwin environment, none of the cygwin paths are valid anymore. Vim doesn't know how to interpret /cygpath/c or /bin/bash or any of that. Native Windows Vim speaks native Windows file paths.
>
> You MIGHT be able to fix this by setting the 'shell' option, and possibly also 'shellquote', 'shellxquote', and optionally 'noshellslash'. But I'm not sure. Your best bet would be not to call native Windows applications from cygwin.
>
> You might also be able to set 'diffexpr' to a function which will select the correct diff, and also translate the paths passed in by cygwin.
>

I will try this an report later if it works.

thanks.

Ben Fritz

unread,
Jul 12, 2012, 1:29:09 PM7/12/12
to vim...@googlegroups.com
On Thursday, July 12, 2012 8:28:52 AM UTC-5, skeept wrote:
> > is it possible for you to turn off the HTML formatting in whatever client you're using? It isn't translating properly on the Google Groups interface. I don't know what it looks like in an email.
>
> Sorry about that, I am just using the page in google groups to write the message, google groups is doing that by itself.
>

Now, that's funny. I've never had problems with it before. I'm using the Google Groups interface as well, but somehow this list uses a plaintext while other lists I'm on use "rich text" editors. I'm not sure if there's a hidden settings somewhere that I've forgotten about, or what.

Do other people see the HTML editor, or the plaintext editor, for this list on Google Groups?

Ben Fritz

unread,
Jul 12, 2012, 1:43:09 PM7/12/12
to vim...@googlegroups.com
On Thursday, July 12, 2012 12:29:09 PM UTC-5, Ben Fritz wrote:
>
> Now, that's funny. I've never had problems with it before. I'm using the Google Groups interface as well, but somehow this list uses a plaintext while other lists I'm on use "rich text" editors. I'm not sure if there's a hidden settings somewhere that I've forgotten about, or what.

>
> Do other people see the HTML editor, or the plaintext editor, for this list on Google Groups?

It's doing it for me, too. I've reported it to Google from the little gear icon at the top of the page. We'll see if anything comes of it.

Bram Moolenaar

unread,
Jul 12, 2012, 2:33:48 PM7/12/12
to Ben Fritz, vim...@googlegroups.com

Ben Fritz wrote:

> On Thursday, July 12, 2012 8:28:52 AM UTC-5, skeept wrote:
> > > is it possible for you to turn off the HTML formatting in whatever client you're using? It isn't translating properly on the Google Groups interface. I don't know what it looks like in an email.
> >
> > Sorry about that, I am just using the page in google groups to write the message, google groups is doing that by itself.
> >
>
> Now, that's funny. I've never had problems with it before. I'm using
> the Google Groups interface as well, but somehow this list uses a
> plaintext while other lists I'm on use "rich text" editors. I'm not
> sure if there's a hidden settings somewhere that I've forgotten about,
> or what.

I'm not sure if there is a public setting now. I asked the right
question to the right team and they switched the Vim group to plain
text.

> Do other people see the HTML editor, or the plaintext editor, for this
> list on Google Groups?

--
Two percent of zero is almost nothing.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

skeept

unread,
Jul 13, 2012, 9:16:44 AM7/13/12
to vim...@googlegroups.com
On Thursday, July 12, 2012 8:28:52 AM UTC-5, skeept wrote:
> > is it possible for you to turn off the HTML formatting in whatever client you're using? It isn't translating properly on the Google Groups interface. I don't know what it looks like in an email.
>
> Sorry about that, I am just using the page in google groups to write the message, google groups is doing that by itself.
>
> > You started a native-windows Vim from a cygwin shell. So Vim thinks the shell is whatever cygwin has it set to. However, once the native Vim is running outside of the cygwin environment, none of the cygwin paths are valid anymore. Vim doesn't know how to interpret /cygpath/c or /bin/bash or any of that. Native Windows Vim speaks native Windows file paths.
> >
> > You MIGHT be able to fix this by setting the 'shell' option, and possibly also 'shellquote', 'shellxquote', and optionally 'noshellslash'. But I'm not sure. Your best bet would be not to call native Windows applications from cygwin.
> >
> > You might also be able to set 'diffexpr' to a function which will select the correct diff, and also translate the paths passed in by cygwin.
> >
>
> I will try this an report later if it works.
>

It does work if I change the value of shell, I don't even need to change the value of $TMP or shellxquote.
So now I have:


if has("win32")
"let $TMP = 'c:\\htemp\\tmp'

set shell=C:\Windows\System32\cmd.exe
"set shellxquote=(
endif

what I would like to have is
if has("win32") and shell.find('bash') >= 0


"let $TMP = 'c:\\htemp\\tmp'

set shell=C:\Windows\System32\cmd.exe
"set shellxquote=(
endif

my question now is how do this test, to check if the string bash is in shell?

Thank you.

Ben Fritz

unread,
Jul 13, 2012, 11:13:22 AM7/13/12
to vim...@googlegroups.com
On Friday, July 13, 2012 8:16:44 AM UTC-5, skeept wrote:
>
> what I would like to have is
> if has("win32") and shell.find('bash') >= 0
> "let $TMP = 'c:\\htemp\\tmp'

> set shell=C:\Windows\System32\cmd.exe
> "set shellxquote=(

> endif
>
> my question now is how do this test, to check if the string bash is in shell?
>
> Thank you.

You can access any option's value in a script by prepending '&' to the option name.

So in this case, you'd test for bash with something like:

" test for bash on Windows
if has('win32') && &shell =~ 'bash'

Or even better:

" test for pretty much any Unixy shell on Windows
if has('win32') && &shell =~ 'sh$'

or:

" test for Windows not using the default Windows shell
if has('win32') && &shell !~ 'cmd'

skeept

unread,
Jul 13, 2012, 1:53:09 PM7/13/12
to vim...@googlegroups.com
On Friday, July 13, 2012 10:13:22 AM UTC-5, Ben Fritz wrote:
> On Friday, July 13, 2012 8:16:44 AM UTC-5, skeept wrote:
> >
> > what I would like to have is
> > if has("win32") and shell.find('bash') >= 0
> > "let $TMP = 'c:\\htemp\\tmp'
> > set shell=C:\Windows\System32\cmd.exe
> > "set shellxquote=(
> > endif
> >
> > my question now is how do this test, to check if the string bash is in shell?
> >
> > Thank you.
>
> You can access any option's value in a script by prepending '&' to the option name.
>
> So in this case, you'd test for bash with something like:
>
> " test for bash on Windows
> if has('win32') && &shell =~ 'bash'
>
> Or even better:
>
> " test for pretty much any Unixy shell on Windows
> if has('win32') && &shell =~ 'sh$'
>
> or:
>
> " test for Windows not using the default Windows shell
> if has('win32') && &shell !~ 'cmd'

Thanks, I didn't know about these =~ and !~ operators. They seem to be similar to the ones in perl that I have trying to learn lately.

Best Regards,
Jorge

Reply all
Reply to author
Forward
0 new messages