Michael Cranston

SublimeText - Conditionally Removing Trailing Spaces

Trailing white spaces are annoying. Forunately, SublimeText automates this for us by simpling adding this options to our Sublime config:

"trim_trailing_white_space_on_save": true

Except we are screwed if we use a templating language. Because whitespace will be trimmed in nested element which means you won’t have a space between words. (Without littering your Jade with .)

Thanks to StackOverflow user myk-willis, there’s a solution:

  1. Add trim_trailing_white_space_on_save to your Sublime user config (presuming you want this as your default).
  2. Open a file-type where you do not want non-breaking spaces (i.e. Jade).
  3. Go to Preferences > Settings-More > Syntax Specific and allow trailing spaces for that specific syntax:
{
"trim_trailing_white_space_on_save": false
}
comments powered by Disqus