How to trim or delete trailing white spaces automatically on save in Sublime Text 2

Sublime_Text_Logo

Sublime Text 2 is my opinion one of most beautiful and useful editors for web developers, of course I really like Notepad++ (but this one, it doesn’t have a version for MAC OSX). A common task when we are creating awesome source codes is trim/delete trailing white spaces, because these are not good and even they could bring on some issues in programming. So, if you want to do this automatically when you save your files and you are using Sublime Text 2, then is really easy, please just:

1) Click on: Sublime Text 2 > Preferences > Settings – User

2) This will open a file with a JSON format configuration.

3) Add the next configuration parameter to your Sublime Text 2:

"trim_trailing_white_space_on_save" : true

In my case my configuration file looks like this:

{
	"color_scheme": "Packages/Color Scheme - Default/Eiffel.tmTheme",
	"font_size": 14.0,
	"ignored_packages":
	[
		"Vintage"
	],
	"trim_trailing_white_space_on_save" : true
}

Note: It is important the comma “,” before the line “trim_trailing_white_space_on_save” : true in order to avoid error in your configuration file.

trim-white-spaces-sublime-text-2

For Windows users

I think, Sublime Text 2 – Windows version has an alike option, please look for this and follow the same procedure.

That’s it. Be happy with your code!

Alex Arriaga

Leave a Reply

Your email address will not be published. Required fields are marked *