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.
You can simply use a regex to remove trailing whitespaces:
[^\S\r\n]+$
[^\S\r\n]+$
is Regex for "at least one whitespace character (so spaces and tabs but not newlines, using a double negation) followed by the end of the line"Here's a super simple way that uses no plugins or settings and works in most situations.
The spaces and tabs at the end of the lines should now be selected. Press Delete or Backspace
Note - Special characters such as ( and + may also be selected at the end of the line at this point, not just spaces.
How to Multi-Select all lines:
One way is to use the middle mouse key to select vertically then hit the End Key if it's a small selection.
With hot-keys:
You can also use the find function to find something that will be in every line, like the space character:
Sample Text:
I use these steps for a quick on-demand solution within Sublime Text:
[ \t]+\n
\n
You could also do this for a large set of files via
[ \t]+\n
\n
Beware: using this plugin makes Sublime Text significantly slower
I use TrailingSpaces plugin for this.
Usage: click "Edit / Trailing Spaces / Delete".
To add a key binding, open "Preferences / Key Bindings - User" and add:
I found a soulution here: http://www.sublimetext.com/forum/viewtopic.php?f=4&t=4958
You can modify the package
located in the default packages directory, this way:
Now you can add the command to your keymap configuration: