Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vimdiff failing with "Cannot read or write temp files"

Tags:

vim

I'm using Vim 7.4 on Windows 7.

I do have a custom _vimrc file, but both Vim and gVim work fine. When I try to run vimdiff .\xxxxx .\yyyyy, it gives the error

Cannot read or write temp files

like image 448
AppFzx Avatar asked Feb 18 '14 18:02

AppFzx


6 Answers

This issue can be caused by the default _vimrc file created by the installer on Windows. If you're still using that default file, or if you copied it at some point, then check the function you've assigned to the diffexpr option. One of the patches between Vim 7.3 and 7.4 introduced new default quoting rules for the cmd.exe shell on Windows. This patch broke the workaround in the MyDiff() function designed to fix the same issue solved by the patch.

The MyDiff() function was fixed by version 7.4.103 by fixing the installer. Here is the MyDiff() function which the latest installer will create for you if you just want to copy it to your _vimrc:

 function MyDiff()
   let opt = '-a --binary '
   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
   let arg1 = v:fname_in
   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
   let arg2 = v:fname_new
   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
   let arg3 = v:fname_out
   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
   if $VIMRUNTIME =~ ' '
     if &sh =~ '\<cmd'
       if empty(&shellxquote)
         let l:shxq_sav = ''
         set shellxquote&
       endif
       let cmd = '"' . $VIMRUNTIME . '\diff"'
     else
       let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
     endif
   else
     let cmd = $VIMRUNTIME . '\diff'
   endif
   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
   if exists('l:shxq_sav')
     let &shellxquote=l:shxq_sav
   endif
 endfunction

You can see your full version in Vim using the :version or :intro commands, or at the splash screen at startup.

The official Vim 8.0 installer is now available, or you can install a nightly build, install Vim from other places or build your own Vim. Installing with any of these methods should get you the latest default vimrc file if you want to grab the latest incarnation of this function.

Copied from my answer to this same question on Super User.

like image 185
Ben Avatar answered Oct 24 '22 00:10

Ben


Adding:

set shell=c:\cygwin64\bin\bash.exe

to my _vimrc worked for me.

like image 7
Don Mitchell Avatar answered Oct 24 '22 02:10

Don Mitchell


I was getting this exact error and had uselessly fiddled around with the permissions on set backupdir.

But then I remembered that I have recently changed to Windows 7 and to using Cygwin 64 and had forgotten to repoint the following setting.

set shell=c:\\cygwin64\\bin\\zsh.exe shellcmdflag=-c shellxquote=\"

And hey presto the error went away and the following now works:

gvim -d v1.php v2.php

So what this error is really saying is I can't find your shell or cmd!

like image 4
zzapper Avatar answered Oct 24 '22 01:10

zzapper


I installed Vim 8.0 on Windows 7. After adding the directory containg vim to my PATH variable "diffthis" etc. worked out of the box if called from a CMD command line. But calling gvim from a cygwin bash resulted in error "E97: cannot create diff".

The following _vimrc (inspired by this and this post) solved the problem with cygwin and it also works with Windows commandline:

runtime vimrc_example.vim
" Change path to bash with your workstation specific path
set shell=C:\Programme\cygwin\bin\bash
" Override value of TMP from cygwin (normally set to /tmp)
let $TMP="c:/tmp"

Note that with the _vimrc above you lose gvim's Windows-specific behavior like using CTRL-V for pasting etc (you can use SHIFT-Ins anyhow). But with enabled Windows-specific behavior (like in the generated _vimrc during install) gvim failed to perform "diffthis" with "E97:..." error.

like image 1
user -27 Avatar answered Oct 24 '22 02:10

user -27


I also was getting the messages

E810: Cannot read or write temp files
E97: Cannot create diffs

However my _vimrc file was fine.

The issue was that C:\Program Files\Vim\vim74 was not in the PATH environment variable, so Vim could not launch diff.exe.

like image 1
Joe Bonds Avatar answered Oct 24 '22 02:10

Joe Bonds


Vim 8.1

I was experiencing this issue, and this answer resolved it for me.

Add this to your ~/.vimrc

set shell=$COMSPEC

For me using git for windows, this value is: C:\WINDOWS\system32\cmd.exe

Also note that in this thread every answer other than the top answer relates to changing your shell variable. So if you're someone who has stumbled upon this answer, try taking a look at that.

like image 1
nanotek Avatar answered Oct 24 '22 02:10

nanotek