How do I add white space characters to Sublime Text 2?

Why is this necessary? I want to know where my tabs and spaces are and if any crazy characters are being added.

First the solution came from two great articles (article one, article two)

Here is a quick and down and dirty summarization of the two articles:

So if you want to see hidden characters open user settings:
Select User Settings from the drop down menu

When that file opens add this code

[prettify]
“draw_white_space”: “all”
[/prettify]

Once you save it you will see the hidden characters. Great! But wait. We always see them. We want a way to use a key (let’s use the F8 key to toggle hidden characters on and off.)

How? Simple. Just create a new plugin:
Add a new plugin with ST2

When that file opens up, just add this code:

[prettify]
import sublime
import sublime_plugin

class ToggleWhiteSpaceCommand(sublime_plugin.ApplicationCommand):
def run(self):
settings = sublime.load_settings(“Preferences.sublime-settings”)
white_space = “selection” if settings.get(“draw_white_space”, “selection”) != “selection” else “all”
settings.set(“draw_white_space”, white_space)
sublime.save_settings(“Preferences.sublime-settings”)
[/prettify]

Now you have to open the User key bindings (this will allow you to use F8 to toggle the hidden characters on/off):
Open the user key bindings from the ST2 menu

Add this code and you are ready to rock and roll:

[prettify]
{
“keys”: [“f8”],
“command”: “toggle_white_space”
}
[/prettify]

Simple and Efficient. Enjoy.

Leave a Reply

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