Alexander Popov
Alexander Popov

Reputation: 24875

Diff syntax highlighting in Visual Studio Code?

Is there an extension or setting, which makes a file with a .diff extension, opened in VS Code, display added lines in green and deleted lines in red? Currently, when I open a diff file, it displays added and deleted lines in the same color. I'm using VS Code Version: 1.37.1.

P.S. I tried the diff extension, but it doesn't work for me.

P.P.S. I tried reloading VS Code with extensions disabled and the highlighting is still broken:

enter image description here

Upvotes: 3

Views: 5778

Answers (3)

pfg
pfg

Reputation: 3577

Adding syntax highlighting overrides can fix this on themes where diff doesn't work:

ctrl+shift+p: Open User Settings (JSON)

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "markup.deleted",
                "settings": {
                    "foreground": "#FF0000",
                },
            },
            {
                "scope": "markup.inserted",
                "settings": {
                    "foreground": "#00FF00",
                },
            },
        ],
    },

(Token scopes can be found by ctrl+shift+p: Inspect tokens and scopes)

Upvotes: 0

Loner
Loner

Reputation: 309

I observed that .diff files are highlighted by default(without requiring any extensions), it's just that certain themes do not work well. Theme-Winter is coming

Theme-Dracula at night

Upvotes: 8

FcoJavier99
FcoJavier99

Reputation: 327

VS Code currently have this feature, if you get the .diff extension the sintax highlight performs correctly like git bash.

My VS Code is:

Version: 1.47.2 (system setup)
Commit: 17299e413d5590b14ab0340ea477cdd86ff13daf
Date: 2020-07-15T18:22:06.216Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 6.3.9600

Upvotes: 2

Related Questions