30

I recently installed the 7.4 version of gVim on a Windows 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% environment variables are populated 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 it looked like something was changed in v7.4.

How can I diff the two files?

1 Answer 1

47

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 if you want an official installer, you will either need to wait until 8.0, or install a nightly build. Nevertheless, you can install Vim from other places or build your own Vim.


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

22
  • 1
    Found a few solutions on then net, but this is the only one that worked for me!
    – ysap
    Jan 7, 2014 at 18:43
  • BTW - how can you tell the # of the sub-version (e.g. 7.4.103)?
    – ysap
    Jan 7, 2014 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, 2014 at 23:50
  • 1
    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, 2014 at 23:52
  • 1
    @Ben I've fixed the issue, it was something else causing this, and I misunderstood this MyDiff() to be something to use when using vim on windows, but it's for something for using vim through cmd, I am using vim through git bash. Thank you. Oct 5, 2015 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .