Is there a way to remove trailing spaces in Visual Studio Code (automatically or with a shortcut)?
I've been looking for this in the command palette and in the editor settings, but I cannot find what I am looking for.
Is there a way to remove trailing spaces in Visual Studio Code (automatically or with a shortcut)?
I've been looking for this in the command palette and in the editor settings, but I cannot find what I am looking for.
In recent Visual Studio Code versions you can find settings here:
Menu File → Preference → Settings → Text Editor → Files → (scroll down a bit) Trim Trailing Whitespace
This is for trimming whitespace when saving a file.
Or you can search "Trim Trailing Whitespace" in the top search bar.
Have a look at the EditorConfig plugin.
By using the plugin you can have settings specific for various projects. Visual Studio Code also has IntelliSense built-in for .editorconfig files.
1) Go to File
> Preferences
> Settings
:
2) In the search bar type file trailing
:
3) Check the option
You're all set. Now if you add space(s) at the end of a line (or even consecutive spaces in the middle of a line), once you Ctrl+S, the additional useless spaces will get automatically removed.
Easiest for me was to open the settings.json
file in the .vscode
folder in my working folder and insert the above mentioned line:
"files.trimTrailingWhitespace": true
There is extension in VS Code. This can also be used.
Name: Trailing Spaces Id: shardulm94.trailing-spaces Description: Highlight trailing spaces and delete them in a flash! Version: 0.4.1 Publisher: Shardul Mahadik VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=shardulm94.trailing-spaces
You can enable whitespace trimming at file save time from settings:
"files.trimTrailingWhitespace": true
setting to the User Settings document if it's not already there. This is so you aren't editing the Default Setting directly, but instead adding to it.We also added a new command to trigger this manually (Trim Trailing Whitespace from the command palette).