Removing the whitespace from text files in Sublime

I like Sublime Text, it's my favourite text editor. Handily available for OSX and Windows.

What's annoying though is when you get given or open a text file that has loads of whitespace at the end of the lines. Aside from messing with my compulsive sense of order, there are cases when extra whitespace can cause problems for some applications.

Just in case, there's a handy configuration option that can strip out trailing whitespace when a file is saved. Here's how to set it up…

  1. Open Sublime's preferences – in OSX this is done by “cmd + ,”
  2. Add the setting “trim_trailing_white_space_on_save” and set it to “true”
  3. Save the preferences file

Bingo! Whitespace will be trimmed when files are saved in future.

Just for clarity, the full setting in a fresh config file looks like this:

{
"trim_trailing_white_space_on_save": true
}