通过 Git 使用 Vimdiff 时如何获取 bufspec

发布于 2024-08-26 14:23:15 字数 1105 浏览 12 评论 0原文

我读过 Vimdiff查看与 Vimdiff 的差异,并使用“vimdiff multiple”、“vimdiff git”、“vimdiff 命令”等进行各种 google 搜索。

使用 do 或 diffg 时,出现错误“在 diff 模式下有两个以上缓冲区,不知道使用哪一个”。

当使用 diffg v:fname_in 时,我得到“没有 v:fname_in 匹配的缓冲区”。

来自 vimdiff 文档:

:[范围]diffg[et] [bufspec]
修改当前缓冲区以消除与另一个缓冲区的差异 缓冲。如果给出 [bufspec],则使用该缓冲区。如果 [bufspec] 指的是当前缓冲区,则什么也不会发生。 否则,只有当 diff 中有另一个缓冲区时,这才有效 模式。

还有更多:

当 'diffexpr' 不为空时,Vim 计算以获取 diff 文件 提到的格式。这些变量设置为使用的文件名:

原始文件中的v:fname_
v:fname_new 同一文件的新版本
v:fname_out 生成的差异文件

因此,我需要获取 bufspec 的名称,但未设置默认变量(fname_in、fname_new 和 fname_out)。

我通过终端在 Linux 机器上运行命令 git mergetool 。

[编辑] 部分解决方案引发了更多问题。我在缓冲区底部使用了“文件名”。这只是一个一半的答案,因为偶尔我会收到文件不存在的错误。我相信它始终是“不存在”的文件的远程版本。我怀疑这与 git 和索引有关。

通过 git-mergetool 使用 vimdiff 时如何一致获取 bufspec 值?

I've read Vimdiff and Viewing differences with Vimdiff plus doing various google searches using things like "vimdiff multiple", "vimdiff git", "vimdiff commands" etc.

When using do or diffg I get the error "More than two buffers in diff mode, don't know which one to use".

When using diffg v:fname_in I get "No matching buffer for v:fname_in".

From the vimdiff documentation:

:[range]diffg[et] [bufspec]
Modify the current buffer to undo difference with another
buffer. If [bufspec] is given, that buffer is used. If
[bufspec] refers to the current buffer then nothing happens.
Otherwise this only works if there is one other buffer in diff
mode.

and more:

When 'diffexpr' is not empty, Vim evaluates to obtain a diff file in the
format mentioned. These variables are set to the file names used:

v:fname_in original file
v:fname_new new version of the same file
v:fname_out resulting diff file

So, I need to get the name of bufspec, but the default variables (fname_in, fname_new, and fname_out) aren't set.

I ran the command git mergetool on a linux box through a terminal.

[Edit]
A partial solution that bred more questions. I used the "filename" at the bottom of the buffer. It's only a half answer, because occasionally I get a file does not exist error. I believe it's consistently the remote version of the file that "does not exist". I suspect this has something to do with git and indexing.

How do you get the bufspec value consistently while using vimdiff through git-mergetool?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眉黛浅 2024-09-02 14:23:15

上面的 [bufspec] 参数可以是缓冲区编号、缓冲区名称的模式或缓冲区名称的一部分。示例:

  • :diffget 使用另一个处于 diff 模式的缓冲区
  • :diffget 3 使用缓冲区 3
  • :diffget v2 使用与 v2 并且位于
    diff 模式(例如,file.c.v2

我总是使用缓冲区的编号。

The [bufspec] argument above can be a buffer number, a pattern for a buffer name or a part of a buffer name. Examples:

  • :diffget Use the other buffer which is in diff mode
  • :diffget 3 Use buffer 3
  • :diffget v2 Use the buffer which matches v2 and is in
    diff mode (e.g., file.c.v2)

I always use the number of the buffer.

万劫不复 2024-09-02 14:23:15

输入 "2" ,然后按 ctrl-g ,它会显示缓冲区编号和文件。

Type in "2" , and then ctrl-g , it shows you the buffer number, and the file.

π浅易 2024-09-02 14:23:15

要列出可用的缓冲区编号和名称(bufspec 的有效值),请使用 :ls

(从这个问题的标题来看,这就是我认为被问到的问题,并且是为什么我看这里。)

:ls 将列出缓冲区编号和名称。当前包含光标的窗口将用 % 表示:

:ls
  1 #a   "Gemfile.lock"                 line 1
  2 %a   "Gemfile.lock.LOCAL.4828.lock" line 1
  3  a   "Gemfile.lock.BASE.4828.lock"  line 0
  4  a   "Gemfile.lock.REMOTE.4828.lock" line 0

当使用 diffgetdiffput 时,任何与缓冲区名称唯一匹配的子字符串都可以用作 bufspec 参数。例如,假设上述代码段中反映的状态,我们可以使用:

diffget REM

来获取 Gemfile.lock.REMOTE.4828.lock 的更改版本当前位于光标下方。

To list the available buffer numbers and names (valid values for bufspec), use :ls

(From the title of this question, that's what I thought was being asked, and was why I looked here.)

:ls will list the buffer numbers and names. The window currently containing the cursor will be denoted by a %:

:ls
  1 #a   "Gemfile.lock"                 line 1
  2 %a   "Gemfile.lock.LOCAL.4828.lock" line 1
  3  a   "Gemfile.lock.BASE.4828.lock"  line 0
  4  a   "Gemfile.lock.REMOTE.4828.lock" line 0

When using diffget or diffput, any substring that uniquely matches a buffer name can be used as the bufspec argument. For example, assuming the state reflected in the above snippet, we can use:

diffget REM

to grab Gemfile.lock.REMOTE.4828.lock's version of the change that is currently under the cursor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文