Powershell中的vimdiff E97 [英] vimdiff E97 in Powershell

查看:155
本文介绍了Powershell中的vimdiff E97的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让vimdiff在Windows 10计算机上工作.我正在Powershell中运行vim. Powershell在$myvimrc中也被声明为我的选择外壳程序:

I am having trouble getting vimdiff to work on a Windows 10 machine. I am running vim from Powershell. Powershell is also declared in $myvimrc as my shell of choice:

set shell=C:\WINDOWS\system32\WindowsPowershell\v1.0\powershell.exe

我尝试比较的文档未保存为文件.我打开两个垂直拆分,在每个拆分中输入文本,然后运行:windo diffthis.输出为E97: Cannot create diffs.

The documents I am attempting to compare are not saved as files. I open two vertical splits, enter text into each, and run :windo diffthis. The output is E97: Cannot create diffs.

这篇文章说,我可能需要下载和使用不同于本文档的diff.exe一个安装了gvim.我已经下载了推荐的"GnuWin32 diff"软件包,并将安装目录添加到了Windows路径($env:path).继续遵循这些指示,我注释掉了默认的diffexpr声明,但仍然得到E97.

This article says I may need to download and use a different diff.exe than the one installed with gvim. I have downloaded the recommended "GnuWin32 diff" package and added the install directory to my Windows Path ($env:path). Continuing to follow these directions, I've commented out the default diffexpr declaration, but still get E97.

我也曾尝试调用自己的函数无济于事.在此尝试中,我确保转义了反斜杠,并且还将下载的diff.exe复制到了我确信自己具有完全许可权的目录中.为了帮助进行故障排除,我暂时保存了我想比较的两个文件,并显式地指定了它们的完整路径,而不是使用vim的v:fname_inv:fname_new(和v:fname_out).

I have also tried calling my own function to no avail. In this attempt, I've made sure to escape backslashes, and have also copied the downloaded diff.exe to a directory I am confident I have full permissions to. To help with troubleshooting, I've temporarily saved the two files I wish to compare, and specified their full paths explicitly rather than using vim's v:fname_in and v:fname_new (and v:fname_out).

set diffexpr=TestDiff()
function TestDiff()
       silent execute "!& " . "C:\\diff.exe" . " -a --binary " "C:\\a.edi" . " " . "C:\\b.edi" . " > " . "C:\\tmp.txt"
endfunction

我通过运行:h E97研究了此错误,该错误返回以下信息:

I've researched this error by running :h E97, which returns the following information:

如果diff输出看起来还不错,Vim将进行测试.如果没有, 您将收到一条错误消息.可能的原因:

Vim will do a test if the diff output looks alright. If it doesn't, you will get an error message. Possible causes:

  • "diff"程序无法执行.
  • 差异"程序不会产生普通的"ed"样式差异(请参见上文).
  • 'shell'和关联的选项设置不正确.尝试使用:!sort"之类的命令进行过滤.
  • 您正在使用'diffexpr',它不起作用.如果不清楚是什么问题,请将详细"选项设置为一个或多个以查看 更多消息.
  • The "diff" program cannot be executed.
  • The "diff" program doesn't produce normal "ed" style diffs (see above).
  • The 'shell' and associated options are not set correctly. Try if filtering works with a command like ":!sort".
  • You are using 'diffexpr' and it doesn't work. If it's not clear what the problem is set the 'verbose' option to one or more to see more messages.

用于MS-Windows的自动安装的Vim包含一个diff程序.如果 您没有它,可能要下载diff.exe.例如 来自 http://gnuwin32.sourceforge.net/packages/diffutils.htm .

The self-installing Vim for MS-Windows includes a diff program. If you don't have it you might want to download a diff.exe. For example from http://gnuwin32.sourceforge.net/packages/diffutils.htm.

我相信我会通过这些要求中的前两个,因为会生成tmp.txt并遵循帮助文件中提供的示例"ed"样式diff.我没有在$myvimrc中设置其他与Shell相关的参数(shelltype,shellpipe等),但是在:!完整的情况下执行其他命令也没有问题.

I believe that I pass the first two of these requirements, as tmp.txt is generated and follows the example "ed" style diff that is provided in the help file. I have not set other shell-related parameters (shelltype, shellpipe, etc) in $myvimrc, but executing other commands with :! complete without issue.

:messages中没有其他信息,只有E97错误.

There is no additional information in :messages, only the E97 error.

修改: 如果我从$myvimrc中删除set shell=C:\WINDOWS\system32\WindowsPowershell\v1.0\powershell.exe,则将外壳默认设置回cmd.exe,则diffthis会按预期工作.似乎其他人在使用Powershell时也遇到了这个问题.

If I remove set shell=C:\WINDOWS\system32\WindowsPowershell\v1.0\powershell.exe from $myvimrc, defaulting the shell back to cmd.exe, diffthis works as expected. It seems that others have also had this problem when using Powershell.

下面是同时在两个shell上运行diffthis时弹出的命令窗口的捕获.使用的命令几乎完全相同.

Below are captures of the command windows that pop up when running diffthis with both shells. The commands used are nearly identical.

我曾推测,这种尝试在Powershell版本中出现的正斜杠是有问题的,但是我能够准确地运行此命令(用伪文件代替.tmp文件),并且它输出的似乎是与diff一起使用的足够文件.我也尝试过添加substitute正斜杠与反斜杠无济于事.

I had speculated that the forward slashes apparent in the Powershell version of this attempt were problematic, but I am able to run this command exactly (with dummy files in place of the .tmp files) and it outputs what seems to be an adequate file for use with diff. I've also tried adding a substitute of forward slashes to back slashes to no avail.

推荐答案

问题归结为vim/Powershell的使用方式A)将命令封装在引号中,以及B)处理路径名中的空格.

The problem boils down to how vim/Powershell are A) encapsulating the command in quotes and B) handling white space in path names.

我可以通过对$myvimrc进行以下更改来绕过此问题:

I am able to bypass this problem with the following changes to $myvimrc:

set shell=powershell
set shellcmdflag=-c
set shellquote="
set shellxquote=

还更改了if中默认的MyDiff()函数,该函数将cmd变量中的diff设置为路径:

Also a change in the default MyDiff() function within the if that sets the path to diff in the cmd variable:

  " below is the default
  " let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
  let cmd = "C:/diff"

此方法取决于将vim附带的diff.exe复制到目录中,为简单起见,该目录的路径中不包含空格(C:\ diff.exe).

This approach is dependent upon copying the diff.exe that ships with vim to a directory that doesn't contain spaces in the path for simplicity (C:\diff.exe).

执行的结果命令为:

powershell -c C:/diff -a --binary C:/<redacted>/a.tmp C:/<redacted>/b.tmp > C:/<redacted>/c.tmp

这篇关于Powershell中的vimdiff E97的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆