Is it possible to ignore white-space when viewing code differences of a file (generated by GIT) in Visual Studio Code? That will be really helpful in checking for actual code additions/deletions before committing.
I believe OP is asking to ignore all whitespaces (including between words) not just trailing whitespaces.
Unfortunately, it's still not implemented and you can track the process status here: https://github.com/Microsoft/vscode/issues/43026
diffEditor.ignoreLinebreaks
? My search for diffEditor line break seems to have no relevant result. There is a comment that suggests to add ignore line breaks –
Encephalon Add on your settings.json
:
"diffEditor.ignoreTrimWhitespace": true,
scm.diffDecorationsIgnoreTrimWhitespace
if you want to ignore whitespace on gutter indicator. Valid values for it are inherit|true|false
. If you set inherit
, it will inherit from diffEditor.ignoreTrimWhitespace
. –
Industry On the top right corner in diff view, there is a "Show Leading/Trailing Whitespace Differences" button (¶, called pilcrow or paragraph mark) to trim whitespace:
8c91f01fda90388138414d414ace2b230d3331c8
. –
Impudicity I believe OP is asking to ignore all whitespaces (including between words) not just trailing whitespaces.
Unfortunately, it's still not implemented and you can track the process status here: https://github.com/Microsoft/vscode/issues/43026
diffEditor.ignoreLinebreaks
? My search for diffEditor line break seems to have no relevant result. There is a comment that suggests to add ignore line breaks –
Encephalon One idea is to format the documents using the same formatting standard and then compare the files.
If you are searching for a solution that doesn't bluntly ignore all whitespace changes, but only those that don't have an effect on your code, you should look into semantic/structural diffs. They use the grammar rules of the programming language to distinguish whether a whitespace is relevant (e.g. within a string) or optional (e.g. between function arguments).
I had a similar issue and ended up developing my own extension (SemanticDiff) that adds a structural diff mode to VS Code. Here is an example how it ignores whitespace changes:
You can get the extension from the marketplace. I am not aware of any other VS Code extension that implements such a feature.
Outside of VS Code, there are a few more options available, such as difftastic or diffsitter.
© 2022 - 2024 — McMap. All rights reserved.