How can I expand/collapse a diff sections in Vimdiff?

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 add context:n.

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

Leave a Comment