Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove trailing spaces automatically or with a shortcut

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.

like image 440
schankam Avatar asked Jun 17 '15 06:06

schankam


People also ask

Which function is used to remove trailing spaces?

The TRIM function is fully automatic. It removes removes both leading and trailing spaces from text, and also "normalizes" multiple spaces between words to one space character only.


2 Answers

You can enable whitespace trimming at file save time from settings:

  1. Open Visual Studio Code User Settings (menu FilePreferencesSettingsUser Settings tab).
  2. Click the enter image description here icon in the top-right part of the window. This will open a document.
  3. Add a new "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.
  4. Save the User Settings file.

We also added a new command to trigger this manually (Trim Trailing Whitespace from the command palette).

like image 186
Benjamin Pasero Avatar answered Oct 01 '22 10:10

Benjamin Pasero


Menu CodePreferenceSettings

Enter image description here

Check the "Trim Trailing Whitespace" option - "When enabled, will trim trailing whitespace when saving a file".

like image 31
Shivkumar Birnale Avatar answered Oct 01 '22 10:10

Shivkumar Birnale