如何在 Vimdiff 中展开/折叠 diff 部分?
我今天开始使用 vimdiff,并且想做一些我在基于 Windows 的 diff 编辑器上认为理所当然的事情(例如展开/折叠 diff 部分、进行完整文件扩展/仅与上面三个上下文行进行比较或下文等)。我目前只知道以下命令:
键盘快捷键:
do - 将其他窗口的更改获取到当前窗口。
dp - 将当前窗口的更改放入另一个窗口。
]c - 跳转到下一个更改。
[c - 跳转到上一个更改。
Ctrl+W、w - 切换到另一个分割窗口(Ctrl + W 、Ctrl + W 执行相同的操作,以防您稍后松开 Ctrl 键)
有人能指出我吗正确的方向,以便我可以复制类似的功能?
例如,如果我可以展开/折叠差异周围的线,那就太好了。
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 three context lines above or below, etc.). I currently know only the following commands:
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 + W does the same thing, in case you let go of the Ctrl key a bit later)
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除了你提到的那些之外,我在比较时只经常使用以下内容:
:diffupdate
:diffu
->重新计算差异。当进行多次更改后,Vim 不再显示最小的更改时,它很有用。请注意,只有在 vimdiff 内修改了文件时它才有效。否则,:e
重新加载文件。:设置 noscrollbind
->暂时禁用两个缓冲区上的同时滚动,通过:setscrollbind
重新启用并滚动。您要求的大部分内容都是折叠:Vim 用户手册中有关折叠的章节。除了差异之外,我有时会使用:
zo
->打开折叠。zc
->关闭折叠。但你可能会得到更好的服务:
zr
->减少折叠程度。zm
->请再加一层折叠层。甚至:
zR
->我说,完全减少折叠!zM
->折叠大多数!您要求的另一件事,使用 n 行折叠,可以在 找到Vim 参考手册中关于选项的部分,通过 关于 diff 的部分:
设置 diffopt=
,然后更新或添加context:n
。您还应该查看有关 diff 的用户手册部分。
Aside from the ones you mention, I only use the following frequently when diffing:
:diffupdate
:diffu
-> recalculate the diff. It is useful when, after making several changes, Vim isn't showing minimal changes anymore. Note that it only works if the files have been modified inside vimdiff. Otherwise, use::e
to reload the files if they have been modified outside of vimdiff.:set noscrollbind
-> temporarily disable simultaneous scrolling on both buffers, reenable by:set scrollbind
and scrolling.Most of what you asked for is folding: the Vim user manual's chapter on folding. Outside of diffs, I sometimes use:
zo
-> open fold.zc
-> close fold.But you'll probably be better served by:
zr
-> reducing folding level.zm
-> one more folding level, please.Or even:
zR
-> Reduce completely the folding, I said!.zM
-> fold Most!.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:
set diffopt=<TAB>
, then update or addcontext:n
.You should also take a look at the user manual section on diff.
设置 vimdiff 忽略大小写。
启动 vim diff 后,
我发现令人烦恼的是,一个文件的 MySQL 关键字是小写的,而另一个文件是大写的,几乎每隔一行都显示差异。
这会动态更新屏幕,您可以轻松地再次将其关闭。
Set vimdiff to ignore case.
Having started vim diff with
I find that annoyingly one file has MySQL keywords in lowercase, the other uppercase showing differences on practically every other line.
This updates the screen dynamically and you can just as easily switch it off again.
实际上,如果您执行 Ctrl + W、W,则不需要添加额外的 Ctrl。它做同样的事情。
Actually, if you do Ctrl + W, W, you won't need to add that extra Ctrl. It does the same thing.
如前所述,Ctrl + W、W 可用于在窗格之间导航。
现在,您可以单独选择特定更改并将其粘贴到其他窗格,如下所示。在这里,我给出一个例如,好像我想将我的代码从窗格 1 更改为窗格 2,并且当前我的光标位于窗格 1 中。
使用 Shift + V 突出显示一行,然后使用向上或向下键选择您需要的代码段,然后从下面编写的步骤 3 继续粘贴您的更改在另一个窗格中。
使用视觉模式,然后更改它
Ctrl + W, W as mentioned can be used for navigating from pane to pane.
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.
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