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

本文翻译自:How to expand/collapse a diff sections in Vimdiff?

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.). 我今天开始使用vimdiff了,并希望在基于Windows的差异编辑器上做一些我认为理所当然的事情(比如扩展/折叠差异部分,有完整的文件扩展/只有差异,上面有3个上下文行或者以下等)。 I currently know only the following commands : 我目前只知道以下命令:

Keyboard Shortcuts: 键盘快捷键:

  • d o - Get changes from other window into the current window. d o - 从其他窗口更改到当前窗口。

  • d p - Put the changes from current window into the other window. d p - 将当前窗口中的更改放入另一个窗口。

  • ] c - Jump to the next change. ] c - 跳转到下一个更改。

  • [ c - Jump to the previous change. [ c - 跳转到之前的更改。

  • 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) CTRL + Ww - 切换到另一个分割窗口( CTRL + WCTRL + 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. 例如,如果我可以扩展/折叠差异周围的线条会很好。


#1楼

参考:https://stackoom.com/question/mbSr/如何在Vimdiff中展开-折叠差异部分


#2楼

Actually if you do Ctrl+WW , you won't need to add that extra Ctrl . 实际上如果你做Ctrl+WW ,你不需要添加额外的Ctrl Does the same thing. 做同样的事情。


#3楼

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 这会动态更新屏幕,您可以轻松地再次关闭它


#4楼

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,目前我的光标位于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. 使用Shift-v突出显示一行,然后使用向上或向下键选择所需的代码段,并从下面的步骤3继续将更改粘贴到另一个窗格中。

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


#5楼

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. :diffupdate :diffu - >重新计算diff,在进行多次更改后很有用vim不再显示最小的更改。 Note that it only works if the files have been modified inside vimdiff. 请注意,只有在vimdiff中修改了文件后,它才有效。 Otherwise, use: 否则,使用:
    • :e to reload the files if they have been modified outside of vimdiff. :e如果文件已在vimdiff之外修改,则重新加载文件。
  • :set noscrollbind -> temporarily disable simultaneous scrolling on both buffers, reenable by :set scrollbind and scrolling. :set noscrollbind - >暂时禁用两个缓冲区上的同时滚动,重新启用:set scrollbind和scrolling。

Most of what you asked for is folding: vim user manual's chapter on folding . 您要求的大多数是折叠: vim用户手册关于折叠的章节 Outside of diffs I sometime use: 在差异之外,我有时会使用:

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

But you'll probably be better served by: 但你可能会更好地服务于:

  • zr -> reducing folding level. zr - >降低折叠水平。
  • zm -> one more folding level, please. zm - >请多一个折叠级别。

or even: 甚至:

  • zR -> Reduce completely the folding, I said!. zR - >完全减少折叠,我说!
  • zM -> fold Most!. 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参考手册部分找到,通过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上的用户手册部分

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值