Linux 如何在 Vimdiff 中展开/折叠差异部分?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5288875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:30:41  来源:igfitidea点击:

How to expand/collapse a diff sections in Vimdiff?

linuxvimdiffcommand-line-interfacevimdiff

提问by TCSGrad

I've started using vimdiff today, and wanted to do some of the things that I've taken for granted on Windows based diff editors (like expand/collapse a diff section, have full file expansion/only diffs with 3 context lines above or below, etc.). I currently know only the following commands :

我今天开始使用 vimdiff,并且想做一些我在基于 Windows 的差异编辑器上认为理所当然的事情(例如展开/折叠差异部分,具有完整的文件扩展/仅具有 3 个以上上下文行的差异或下面等等)。我目前只知道以下命令:

Keyboard Shortcuts:

键盘快捷键:

  • do- Get changes from other window into the current window.

  • dp- Put the changes from current window into the other window.

  • ]c- Jump to the next change.

  • [c- Jump to the previous change.

  • CTRL+W, w- Switch to the other split window (CTRL+W, CTRL+Wdoes the same thing, in case you let go of the CTRLkey a bit later)

  • do- 从其他窗口获取更改到当前窗口。

  • dp- 将当前窗口的更改放入另一个窗口。

  • ]c- 跳转到下一个更改。

  • [c- 跳转到上一个更改。

  • CTRL+ W, w- 切换到另一个拆分窗口(CTRL+ W, CTRL+W做同样的事情,以防你CTRL稍后松开键)

Could someone point me to the right direction so I could replicate similar features?

有人可以指出我正确的方向,以便我可以复制类似的功能吗?

It would be nice if I could expand/collapse lines around the diffs, for example.

例如,如果我可以在差异周围展开/折叠线,那就太好了。

采纳答案by ninjalj

Aside from the ones you mention, I only use frequently when diffing the following:

除了你提到的那些,我只在区分以下内容时经常使用:

  • :diffupdate:diffu-> recalculate the diff, useful when after making several changes vim's isn't showing minimal changes anymore. Note that it only works if the files have been modified inside vimdiff. Otherwise, use:
    • :eto reload the files if they have been modified outside of vimdiff.
  • :set noscrollbind-> temporarily disable simultaneous scrolling on both buffers, reenable by :set scrollbindand scrolling.
  • :diffupdate:diffu-> 重新计算差异,在进行多次更改后,vim 不再显示最小更改时很有用。请注意,只有在 vimdiff 中修改了文件时,它才有效。否则,请使用:
    • :e如果在 vimdiff 之外修改了文件,则重新加载文件。
  • :set noscrollbind-> 暂时禁用两个缓冲区上的同时滚动,重新启用:set scrollbind和滚动。

Most of what you asked for is folding: vim user manual's chapter on folding. Outside of diffs I sometime use:

您要求的大部分内容是折叠:vim 用户手册关于折叠的章节。在差异之外,我有时会使用:

  • zo-> open fold.
  • zc-> close fold.
  • zo-> 打开折叠。
  • zc-> 关闭折叠。

But you'll probably be better served by:

但您可能会得到更好的服务:

  • zr-> reducing folding level.
  • zm-> one more folding level, please.
  • zr-> 减少折叠级别。
  • zm-> 请再折叠一层。

or even:

甚至:

  • zR-> Reduce completely the folding, I said!.
  • zM-> fold Most!.
  • zR-> 完全减少折叠,我说!。
  • zM-> 折叠最!。

The other thing you asked for, use n lines of folding, can be found at the vim reference manual section on options, via the section on diff:

您要求的另一件事,使用 n 行折叠,可以在vim 参考手册的 options 部分找到,通过diff 部分

  • set diffopt=<TAB>, then update or add context:n.
  • set diffopt=<TAB>,然后更新或添加context:n

You should also take a look at the user manual section on diff.

您还应该查看有关 diff用户手册部分

回答by tubbo

Actually if you do Ctrl+W W, you won't need to add that extra Ctrl. Does the same thing.

实际上,如果您这样做Ctrl+W W,则无需添加额外的Ctrl. 做同样的事情。

回答by zzapper

set vimdiff to ignore case

设置 vimdiff 忽略大小写

Having started vim diff with

已经开始 vim diff

 gvim -d main.sql backup.sql &

I find that annoyingly one file has MySQL keywords in lowercase the other uppercase showing differences on practically every other line

我发现令人讨厌的是,一个文件的 MySQL 关键字是小写的,而另一个大写的则显示几乎所有其他行的差异

:set diffopt+=icase

this updates the screen dynamically & you can just as easily switch it off again

这会动态更新屏幕,您可以轻松地再次将其关闭

回答by Pratheusha KK

ctrl + w, w as mentioned can be used for navigating from pane to pane.

前面提到的 ctrl + w, w 可用于在窗格之间导航。

Now you can select a particular change alone and paste it to the other pane as follows.Here I am giving an eg as if I wanted to change my piece of code from pane 1 to pane 2 and currently my cursor is in pane1

现在您可以单独选择一个特定的更改并将其粘贴到另一个窗格中,如下所示。在这里我给出一个例子,好像我想将我的一段代码从窗格 1 更改为窗格 2,目前我的光标在窗格 1 中

  • Use Shift-v to highlight a line and use up or down keys to select the piece of code you require and continue from step 3 written below to paste your changes in the other pane.

  • Use visual mode and then change it

    1 click 'v' this will take you to visual mode 2 use up or down key to select your required code 3 click on ,Esc' escape key 4 Now use 'yy' to copy or 'dd' to cut the change 5 do 'ctrl + w, w' to navigate to pane2 6 click 'p' to paste your change where you require

  • 使用 Shift-v 突出显示一行并使用向上或向下键选择您需要的代码段,然后从下面编写的第 3 步继续将您的更改粘贴到另一个窗格中。

  • 使用视觉模式,然后改变它

    1 单击“v”这将带您进入可视模式 2 使用向上或向下键选择您需要的代码 3 单击 ,Esc' 转义键 4 现在使用 'yy' 复制或 'dd' 剪切更改 5 执行 ' ctrl + w, w' 导航到 pane2 6 单击“p”将更改粘贴到您需要的位置