Post Self
Post Self

Reputation: 1554

How to show only parts or regions that have changed in VS Code Diff

IntelliJ IDEs have a button called "Collapse Unchanged Fragments", which hides most code lines that have stayed the same and fit the relevant information in way less space. Is there something similar in VS Code? If so, how do you enable it?

Upvotes: 10

Views: 3062

Answers (3)

Mark
Mark

Reputation: 181060

Just to update the accepted answer. In Stable v1.82 are these settings and keybindings:

Diff Editor > Hide Unchanged Regions: Enabled
Diff Editor > Hide Unchanged Regions: Context Line Count
Diff Editor > Hide Unchanged Regions: Minimum Line Count
Diff Editor > Hide Unchanged Regions: Reveal Line Count

settings to hide unchanged regions in a diff editor

Diff Editor > Experimental: Use Version2   // now defaults to enabled/true

and these keyboard shortcuts:

Diff Editor: Collapse All Unchanged Regions
diffEditor.collapseAllUnchangedRegions

Diff Editor: Show All Unchanged Regions
diffEditor.showAllUnchangedRegions

diffEditor.toggleCollapseUnchangedRegions

These three keyboard shortcuts are unbound by default and can be found by searching for "unchanged" in the Keyboard Shortcuts editor.

You can also use the mouse to fold or expand unchanged regions as shown in the demo below. Or double-click on the text nnn hidden lines to unfold.

And also drag the sash bar just above or below the nnn hidden lines text to reveal more of the hidden code.

unchanged region handling in a diff editor by mouse


And there is a toggle collapse/expand unchanged regions button when you have a diff open:

toggle collapsing unchanged regions button

Upvotes: 3

Nathan Palmer
Nathan Palmer

Reputation: 2030

It's been implemented now. See this comment https://github.com/microsoft/vscode/issues/3562#issuecomment-1609725434

"diffEditor.experimental.useVersion2": true,
"diffEditor.experimental.collapseUnchangedRegions": true,

Upvotes: 12

Steffen
Steffen

Reputation: 169

This seems to be impossible in VS Code. The feature has been requested here: https://github.com/microsoft/vscode/issues/3562. But at the current moment, it hasn't been implemented yet.

Upvotes: 8

Related Questions