Klas Mellbourn
Klas Mellbourn

Reputation: 44347

How to color moved lines in git diff in Visual Studio Code

When git shows the diff between two versions, it has the ability to show sections that have moved (as opposed to just added or removed) in a particular color, using the colorMoved = default config option.

In Visual Studio Code the command Git: Open Changes seems to ignore this option. Is it possible to make Code show what lines have moved?

I've looked at the color settings in https://code.visualstudio.com/api/references/theme-color#diff-editor-colors but couldn't find anything there.

Upvotes: 9

Views: 1587

Answers (4)

starball
starball

Reputation: 50094

In VS Code 1.82, you can opt into the new experimental moved code detection by setting diffEditor.experimental.showMoves to true in your settings. Quoting from the 1.82 release notes:

When enabled, code blocks that are moved from one location to a different location in the same file are detected and arrows are drawn to indicate where the code blocks moved to.

Code moves are also detected when they are slightly modified. The Compare button can be used to compare the block before and after the move.

Upvotes: 2

von Brausen
von Brausen

Reputation: 43

Recently implemented feature of VS Code, you need only enable it in the VS Code settings.

Upvotes: 1

DarkPlayer
DarkPlayer

Reputation: 379

I am working on a Visual Studio Code extension called SemanticDiff that can highlight moved code blocks in diffs. It looks like this:

Moved Code in SemanticDiff

It only works with certain programming languages, as it parses the code to also detect moves that contain minor code changes. You can find the list of supported languages and how to install the extension on the SemanticDiff VS Code marketplace page.

Upvotes: 2

tukan
tukan

Reputation: 17337

It is simply not implemented (which can change in the future). If you check the source code it is not mentioned anywhere.

Here is the code which colors the diff editor colors.

Upvotes: 6

Related Questions