Vimdiff 因“无法读取或写入临时文件"而失败 [英] Vimdiff failing with "Cannot read or write temp files"
问题描述
我在 Windows 7 上使用 Vim 7.4.
I'm using Vim 7.4 on Windows 7.
我确实有一个自定义的 _vimrc 文件,但 Vim 和 gVim 都可以正常工作.当我尝试运行 vimdiff .\xxxxx .\yyyyy
时,它给出了错误
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
推荐答案
此问题可能是由 Windows 上的安装程序创建的默认 _vimrc 文件引起的.如果您仍在使用该默认文件,或者您在某个时候复制了它,请检查您分配给 diffexpr
选项的函数.Vim 7.3 和 7.4 之间的补丁之一为 Windows 上的 cmd.exe shell 引入了新的默认引用规则.此补丁破坏了 MyDiff() 函数中的变通方法,该函数旨在修复补丁所解决的相同问题.
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.
MyDiff() 函数已在 7.4.103 版本中通过修复安装程序进行修复.如果您只想将其复制到 _vimrc,这是最新安装程序将为您创建的 MyDiff() 函数:
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
您可以使用 :version
或 :intro
命令在 Vim 中查看完整版本,或者在启动时的初始屏幕上查看.
You can see your full version in Vim using the :version
or :intro
commands, or at the splash screen at startup.
官方 Vim 8.0 安装程序现已可用,或者您可以安装 nightly build、从其他地方安装 Vim 或 构建你自己的 Vim.如果您想获取此功能的最新版本,使用这些方法中的任何一种进行安装都会为您提供最新的默认 vimrc 文件.
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.
这篇关于Vimdiff 因“无法读取或写入临时文件"而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!