Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I recently installed the 7.4 version of gVim on a Win 7 machine. Trying to diff two files from the context-sensitive menu on Windows Explorer, I keep getting the error messages:

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

The two selected files are opened in the two-pane gVim view, and the editor seems to be in diff mode, but the actual differences are not highlighted.

The %TEMP% and %TMP% env. vars are popuated with a valid directory name.

I get the same response when opening the files in a regular gVim session and typing :diffthis in the command prompt.

This used to work properly with Vim 7.3, but looked like something was changed in v7.4.

How can I diff the two files?

share|improve this question

1 Answer 1

up vote 21 down vote accepted

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.

Unfortunately there will probably not be another official installer until 7.5, but you can install Vim from other places or build your own Vim.


Duplicated on stackoverflow (unusually, on-topic on both sites), if this answer is updated so should the other.

share|improve this answer
1  
Found a few solutions on then net, but this is the only one that worked for me! –  ysap Jan 7 at 18:43
    
BTW - how can you tell the # of the sub-version (e.g. 7.4.103)? –  ysap Jan 7 at 21:56
    
Three ways: startup on an empty buffer shows version information including patch level, the :intro command shows the same text, and the :version command gives the information on an "included patches" line. :version also gives a very detailed list of included or excluded features as well. –  Ben Jan 7 at 23:50
    
Also, Bram doesn't usually release any official installers after the initial minor version, e.g. 7.4.0. But there are plenty of places to get an installer for a more recent Vim if you don't feel like compiling, the most often cited probably being here: sourceforge.net/projects/cream/files/Vim –  Ben Jan 7 at 23:52
    
Well, the startup screen and :intro show me the same info (that is, just "7.4"). :version shows "7.4" and elaborates on the compilation time. No patch version number. Your 2nd comment may explain why it is so. It is compiled by mool(at)tororo, which I assume refers to Mr. Moolner. –  ysap Jan 8 at 14:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.