A Developer asked on Stackoverflow platform : –
Is there a way to remove trailing spaces in Visual Studio Code (automatically or with a shortcut)?
The solution to this problem is simple:
Solution 1
Go to File → Preference → Settings → search for “trim”:
Check the “Trim Trailing Whitespace” option – “When enabled, will trim trailing whitespace when saving a file”.
Solution 2
Not only can you change the Visual Studio Code settings to trim trailing whitespace automatically, but you can also do this from the command palette (Ctrl+Shift+P
):
Solution 3
You can also use the keyboard shortcut:
Windows, Linux: Ctrl+K
, Ctrl+X
Mac: ⌘ + k
, ⌘ + x
.
Add comment