Toggle tab stop lines in BBEdit

One of the things I missed when I switched from BBEdit to TextMate several years ago was what I called BBEdit’s “pinstripe” setting, it’s ability to show thin vertical lines at every tab stop. This can be quite helpful with long stretches of code, where it’s easy to lose track of how deeply indented you are, and I’m glad to be able to use it again.

BBEdit tab stops

You can turn the pinstriping on in the Appearance Preferences, but I don’t like setting this preference because it turns it on in every window, which is overkill.

BBEdit tab stop preference

I certainly don’t need the pinstriping when I’m writing a blog post or a report, and I usually don’t need it when coding—I’ve never lost track of indentation in a short script.

What I need is the ability to quickly toggle the pinstriping on and off for a particular window. Thankfully, Bare Bones makes this easy by including the show tab stops property in BBEdit’s AppleScript dictionary. Here’s a short script that toggles the setting for the front window:

applescript:
1:  tell application "BBEdit"
2:    if front window's show tab stops is true then
3:      set front window's show tab stops to false
4:    else
5:      set front window's show tab stops to true
6:    end if
7:  end tell

The is true in Line 2 is redundant, but I think including it makes the conditional easier to read. I call the script “Toggle Tab Stops” and have it saved in BBEdit’s Scripts folder with a keyboard shortcut of ⌃⌥⌘⇥ (that’s Control-Option-Command-Tab).

I make no claims of originality with this script; I’m sure variations on it have been written dozens of times. But it took less time to write than it would have to find someone else’s version.

Update 9/3/12
OK, I blew this one. It’s not that the script doesn’t work, it’s that it’s unnecessary. Apparently I’ve never looked deeply enough in BBEdit’s menu system to notice the Show Tab Stops item.

Show Tab Stops menu item

So instead of the AppleScript, a better way to toggle this setting is to assign it a keyboard shortcut through the Menu & Shortcuts preference pane.

BBEdit Menu & Shortcuts preferences

Thanks to everyone who pointed this out. Next time I’ll look harder before jumping to a script.


2 Responses to “Toggle tab stop lines in BBEdit”

  1. Lauri Ranta says:

    You can also toggle boolean properties in a single line: tell application "TextWrangler" to tell window 1 to set show tab stops to not show tab stops.

  2. Nathan Grigg says:

    You can also do this from the “Text options” menu in the toolbar. Although you apparently like to hide the toolbar, you can still set a keyboard shortcut for the “Show/Hide Tab Stops” command by looking in the “Menus and Shortcuts” section of the Preferences and looking at the “Toolbar” menu.