Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code - How to stop it deleting whitespaces?

I am using Microsoft's VS Code to edit css, html and ts files that are shared by my team on a VSTS Git repo. However, my VS Code keeps removing empty/whitespaces that my colleagues added when I save any change (Image below) and this screws up the whole Git Diff part, as almost every single line of code shows as a diff. I tried to disable every single config setup but nothings works:

enter image description here

enter image description here

enter image description here

like image 410
SmileyVitaminC Avatar asked Mar 19 '26 06:03

SmileyVitaminC


2 Answers

At the end, what was causing my problem was the extension: EditorConfig for VS Code

This plugin attempts to override user/workspace settings with settings found in .editorconfig files. No additional or vscode-specific files are required. As with any EditorConfig plugin, if root=true is not specified, EditorConfig will continue to look for an .editorconfig file outside of the project.

I believe, it was overriding the options I selected inside of VS Code (such as files.trimTrailingWhitespace: false). So, no setup change I was making was actually being applied.

like image 109
SmileyVitaminC Avatar answered Mar 22 '26 00:03

SmileyVitaminC


It seems you have trailing whitespace enabled in User Preferences too.

I'd suggest opening your configuration file of VSCode using CtrlShiftP or CmdShiftP in Mac and then go to Open User Settings.

I'm sure the next line is around there somewhere, delete it or change it to false.

"files.trimTrailingWhitespace": true
like image 31
Lucas Terracino Avatar answered Mar 22 '26 00:03

Lucas Terracino