Search code examples
whitespacesublimetext2code-cleanup

Sublime Text 2: Trim trailing white space on demand


I know that Sublime Text 2 can delete the trailing white space on files upon saving.

When working in a team and commiting a change to a file this tends to produce huge diffs which make peer code review more cumbersome. For that reason I prefer to only do the white space cleaning when I'm commiting huge changes to a file anyway and leave whitespace as it is for the minor changes.

I would like to know if there's any command for executing the trimming of the white space on demand on a file, other than "Activate trimming on save > Save file > Deactivate trimming".

Searching in the Documentation and on stackoverflow didn't show anything relevant, all the links seem to talk about the auto trimming on save.


Solution

  • Beware: using this plugin makes Sublime Text significantly slower

    I use TrailingSpaces plugin for this.

    Highlight trailing spaces and delete them in a flash.

    ST2 provides a way to automatically delete trailing spaces upon file save. Depending on your settings, it may be more handy to just highlight them and/or delete them by hand. This plugin provides just that!

    Usage: click "Edit / Trailing Spaces / Delete".

    To add a key binding, open "Preferences / Key Bindings - User" and add:

    { "keys": ["ctrl+alt+t"], "command": "delete_trailing_spaces" }