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
}

Michael is a Senior Consultant for Xtravirt. If it's got buttons or flashy lights on it then it'll probably be on his radar. When not "mending computers" (it's sometimes easier than explaining "cloud" to relatives), Michael provides essential education, entertainment and trampoline services to his two children.