How To Configure Sublime Text Show/Hide and Remove Trailing Whitespaces On Save

We have covered enormous tips and how-to on Sublime Text. It’s so great that we can’t wait to share more neat features with you. If you are into development or just interested in specifically configuring Sublime Text the way you want it to be. This guide will be helpful for you, particularly if you want Sublime Text to do some automated work for you, such as removing all the trailing white spaces.

Features like automatically removing trailing white spaces at the end of the line exist in most IDEs, but not so obvious in Sublime Text. Since it is not an IDE, some of the neat things such as removing trailing white spaces are hidden from the menus. This is a quick guide showing you how to configure your Sublime Text to automatically remove any trailing white spaces up on saving a file.

First, go to Preferences → Settings – User

2014-10-20_1114

This will open up the Preferences.sublime-settings file in which you are free to add any flag you are about to use. In this case, add the following key value pair in the JSON formatted file

"trim_trailing_white_space_on_save": true

2014-10-20_1121

Ensure the setting file is still in a valid JSON format, save and close the file. To test to see if it works, you can start adding spaces at the end of a line, save the file. You will notice that as soon as you save the file those white spaces are automatically removed. If you don’t see the spaces being removed, you can turn on the setting to see where there is space in your text file. To do this, add the following line of code into the settings file.

"draw_white_space": "all"

all” is just one of the three options you can pass for this key, additionally you can replace it as “selection” or “none“, meaning that it will draw white space whenever you have selected something, or will not draw white space at all (which was the default setting).

2014-10-20_1116_001

Notice if you have turned on the “draw_white_space” to “all”, each space will be represented as a dot.

2014-10-20_1117

If you have it set to “selection”, whenever you highlight something it draws the dots on only the highlighted part.

In a way, the draw_white_space can also be used to show and hide any white spaces. Use it wisely, and let the machine do as much automated work as possible for you.

For more hidden settings and optional configuration values, check out the Sublime Text unofficial documentation, a very well written unofficial documentation.

Jonathan Hu

Programming by day, Web Development, Canucks & Movies for spare time!
Co-founder of Next of Windows and a cool geek 🙂

Last updated: 10/22/2014

Posted in: How to
Discover more: , , ,

Leave a Reply

Notify of
avatar
wpDiscuz
Today's Top Picks for Our Readers:
Recommended by Recommended by NetLine