Coder Perfect

In Vimdiff, how can I expand/collapse a diff section?

Problem

I just started using vimdiff and wanted to try out some of the features that I’ve come to expect from Windows-based diff editors (such expanding/collapsing a diff section, having entire file expansion/only diffs with three context lines above or below, and so on). I just know the following commands at the moment:

Keyboard Shortcuts:

Could someone please lead me in the appropriate spot so that I can duplicate comparable features?

For example, I’d like to be able to expand/collapse lines around the diffs.

Asked by TCSGrad

Solution #1

I just use the following for diffing, aside from the ones you mentioned.

The chapter on folding in the Vim user handbook covers the majority of what you asked for. Outside of diffs, I’ll occasionally use:

However, you’ll be better served by:

Or even:

The other feature you asked for, using n lines of folding, is covered in the Vim reference manual’s section on options, which is accessible through the section on diff:

You should also check out the user manual portion of the diff website.

Answered by ninjalj

Solution #2

Set vimdiff to disregard case when comparing files.

After starting vim diff,

 gvim -d main.sql backup.sql &

One file includes MySQL keywords in lowercase, while the other has uppercase, resulting in differences on nearly every other line.

:set diffopt+=icase

This dynamically updates the screen, and you can easily turn it off again.

Answered by zzapper

Solution #3

Actually, you won’t need the second Ctrl if you do Ctrl + W, W. It has the same effect.

Answered by tubbo

Solution #4

Ctrl + W, W, as previously indicated, can be used to navigate from one pane to the next.

You can now choose a single change and paste it into the other window as shown below. Here’s an example where I’d like to move my code from pane 1 to pane 2, but my cursor is currently in pane 1.

Answered by Pratheusha KK

Post is based on https://stackoverflow.com/questions/5288875/how-can-i-expand-collapse-a-diff-sections-in-vimdiff