Vimdiff failing with “Cannot read or write temp files”

后端 未结 7 623
一生所求
一生所求 2021-02-02 08:23

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

相关标签:
7条回答
  • 2021-02-02 09:01

    Adding:

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

    to my _vimrc worked for me.

    0 讨论(0)
  • 2021-02-02 09:11

    Have you set vim shell to powershell? If so this answer might work. After hard searching my problem was solved by it.

    At least see what shell you're using, or try to set vim shell to other shells if installed, e.g. set shell=/path/to/bash.exe, it might shed some light.

    0 讨论(0)
  • 2021-02-02 09:16

    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!

    0 讨论(0)
  • 2021-02-02 09:19

    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.

    0 讨论(0)
  • 2021-02-02 09:20

    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.

    0 讨论(0)
  • 2021-02-02 09:21

    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.

    0 讨论(0)
提交回复
热议问题