Moving Text Editors: Taking BBEdit Seriously

January 09, 2012 by Gabe | [mmd] |

There are plenty of good reasons to be eagerly awaiting a stable release of Textmate 2 but there are also equally valid reasons to avoid it. I’ve used both but I’ve never been an expert at either. I’ve used them for small personal projects but nothing that would exercise all of the features. For web development, I use Coda, for python scripts, I use BBEdit and now CodeRunner. Most of my writing for this site is done between Simplenote, NVAlt and MultiMarkdown Composer. Recently I decided to invest myself in BBEdit so I could leverage some of the power it provides.[1]

What I’ve discovered is that BBEdit is an incredibly complicated and simple tool. It’s a plain text editor on the surface, but it’s highly customizable (like Textmate or even Vim). I’ve been documenting some of my experience and this post describes some of what I like about BBEdit 10.

Customizations

Most BBEdit customizations are available by dropping a plain text or AppleScript file in the application support directory. BBEdit makes it easy to access these locations and there are no secret “default writes” voodoo to add new features to BBEdit. It’s all readable text.

Text Clippings

Text clippings are like TextExpander snippets or Keyboard Maestro hotkeys, but more powerful. They are more like Keybindings in their ability to manipulate and select text.

Text clippings in BBEdit have their own vocabulary for performing text substitution and selection, very much like TextExpander insertions. You’ll want to read the manual for this one, but one important term is the #SELECTIONORINSERTION# keyword. This keyword grabs the current selection. If there is not one then the insertion point will be placed here after expanding the clipping. This is very handy for creating custom text wrapping functions. For example auto-wrapping a selection in braces or parentheses.

Wrapping Text

The markdown wrapping I’ve grown accustomed to in NVAlt is great. Select some text and hit the bracket key to surround the text. Or just auto-pairing brackets and parentheses as I type is a time saver. BBEdit provides options for this and much more.

Here is a basic text clipping for bracketing a selection. If there is text selected already, then the text will be enclosed and the insertion point placed to the right of the last bracket. However, if no text is selected then paired brackets are inserted and the insertion point is placed between the brackets.

Here are some not so fancy clippings for markdown:

  1. Surround with hash Marks (##SELECTIONORINSERTION##)
  2. Surround with spaces ( #SELECTIONORINSERTION# )

I can combine these two clippings to quickly make markdown headers by hitting “#” three times and then hitting shift-space to get “### ###” with the insertion mark waiting in the middle. This is a lightning fast way to create MD headers.

Beyond that, I’ve created several clippings for wrapping text in parentheses, braces brackets, asterisks, quotes and literals.

The real power of these clippings are realized when they are associated with keyboard shortcuts. For example, using the “[” key for wrapping selected text just like in NVAlt or MultiMarkdown Composer. But BBEdit will not allow standard system keys to be overriden for clippings.

Keyboard Maestro Overrides

BBEdit will not allow a text clipping to be set to a hotkey that is used by the system.[2] For example, if I want to wrap a selection in brackets, I can not set the clipping to use the “[” key as default. One trick to override this behavior is to [use a Keyboard Maestro group][gruber inetercept] that is only active in BBEdit. That group then contains macros with hotkeys mapped to their BBEdit counter part. Here’s an example. This macro simulates the difficult to remember BBEdit hotkey of ctrl-opt-[ but the macro is triggered by the “[” key.

Trigger Override

Scripts

BBEdit is probably the most scriptable application I have ever worked with. Nearly every aspect of BBEdit can be controlled through AppleScript. But what’s more important, BBEdit provides a mechanism for tying scripts into text clippings[3] and menus. There’s a nice tutorial over at MacTech.

Selection Control

There are plenty of options in BBEdit for moving around a document and selecting text. BBEdit brings a lot to the table right out of the box. But if that’s not enough, just about everything can be customized with AppleScripts.

BBEdit already hase built in support for hopping through text, stoping at CamelCase characters (ctrl-right arrow). But this too could have been done with an AppleScript.

Mr. Gruber has one of the earliest examples I could find of selecting the word that the insertion point is in.

There’s a script to select the current paragraph text, excluding the leading indent and newline characters.

Scripts are made even more powerful when combined with BBEdit’s Grep searching, also accessible through AppleScript. There’s a short tutorial (albeit rather old) at Anybrowser.org.

Sure, BBEdit is scriptable. So are a lot of applications. I was impressed but not surprised about the scripting support. But then I discovered the menu scripting support. Menu scripting provides the ability to add-to and override the BBEdit menus with custom scripts. For example, instead of using the built-in FTP service, there’s a script to override the menu and launch Transmit instead.

Markdown

It’s only natural that BBEdit is one of the premier Markdown environments, given Gruber’s affinity for BBEdit. BBEdit comes with a number of features that support Markdown, but I also installed the Markdown Extensions by Watts Martin. These additional options for getting MD in and out of BBEdit, as well as adding support for MultiMarkdown.

The Markdown language module provides syntax highlighting for links, headings, block quotes, code and lists. There is support for MultiMarkdown through add-ons but the built-in syntax highlighting does not extend to any other MMD features. Fortunately, I use Marked for MMD preview so very little has changed for my writing workflow. I do miss the MMD highlighting though.

Huge win here for BBEdit. If the text exists, BBEdit will find it. BBEdit supports standard Find and Replace, but as mentioned previously, it also supports grep search and replace. If you’re not familiar with grep, check out this short tutorial. Grep is an advanced search function built into UNIX and BBEdit takes full advantage of it. Grep patterns can be saved and recalled at any time. Let’s say you want to match any pattern that looks like a phone number. Grep’s your solution[4]:

[[:digit:]]{3}[ -]\?[[:digit:]]{4}

BBEdit also supports grep searching through AppleScript. Which means a common search can also be tied to a hotkey trigger. For example, a hotkey to automatically select the current word.

Sure, there are good tools for Textmate, like AckMate, but grep is part of BBEdit’s DNA.

BBEdit also supports a beefed up version of good ’ol “Find”, called “Live Search”. when using Live Search, BBEdit begins highlighting matches in the text, as the search term is entered. It’s impressive to see, partly because it is so darn fast. It’s instantaneous on a 1000 paragraphs of text.

Markers

BBEdit provides quick access to functions through a dropdown document menu. When working in Markdown, the menu displays all of the headings with an integer to indicate the heading level. This is nothing ground breaking but it’s nice.

But BBEdit takes quick access one step further with document markers. Markers are like bookmarks within a document. They are invisible in the document text but BBEdit tracks and displays a list of markers when needed. It’s subtle, but very handy. For example, if I’m not happy with a specific piece of text, I can mark it to review later. Another way I’ve been using this feature is to take a break from one section and work on something else. Before I start a new paragraph, I mark the text that I want to revisit. Later, I browse my list of markers to refresh my memory.

The Bad

So it’s not all milk and honey with BBEdit. While I’ve been able to move to BBEdit full time[5] there are still some rough spots.

AppleScript

AppleScript support in BBEdit is both the best and worst things. Almost every function of BBEdit can be accessed through AS. That seems to come at a price though. Unlike Textmate bundles or Sublime Text[6] which can be written in any language, BBEdit is weighed down by AppleScript, which is not versatile or mature enough to do real work. AppleScript is awkward and poorly defined in comparison to other scripting languages. There are too many non-obvious limitations and options. I never know when I should “Tell text of front text window” or more generally “tell front text window”. These are apparently two different things that are only discovered through trial and error.[7]

There’s a lot of AppleScript legacy with BBEdit and it’s likely to remain part of the application until Apple kills it off. I’d like to see BBEdit support additional scripting languages to work on documents.

Color Schemes

BBEdit supports several text coloring options through their Codeless Language Model and their BBColor color schemes. These are nice, but fairly limited. Since BBEdit supports such great grep processing, it seems like that could be leveraged to provide syntax highlighting that is not bounded by a programming language model. For example, why is the Markdown highlighting defined by keywords, numeric constants, string constants and other terms more appropriate for a programming language? I’d like to see a syntax highlighter based on pattern matches that are more general. I’ve found a number of color schemes around the internet but there is no good single source. The closest to a single source I have found is on Github.

Scripting Documentation

The documentation for scripting BBEdit is just “good enough”. Most of what I learned was through extensive Google searching. Many of the examples are very old. There does not appear to be a single repository of AppleScripts to pull from. For an application with such extensive AppleScripting support, it’s frustrating to not have a single repository of examples. However, the Google group for BBEdit is very good and the responses are quick and helpful.

Conclusion

It was worth the investment. I don’t mean just monetarily. I invested many hours into BBEdit and I’m sure there are many more to come. But it was worth it. I have an environment that I feel productive in. I’ve customized it to my exact needs but I’m still producing plain text and working with my other favorite applications like Marked, Simplenote, Dropbox and NVAlt. For the most part, the environment is portable to another Mac, by copying my BBEdit support directory to the new machine.

Advice

I’ll try to avoid the holy wars of text editors and skip the preaching that is abundantly available on the Internet. But if you came here for some advice, I’m happy to share what I think. BBEdit works for me right now. I trust the developers and the product to stick around and keep up support. BBEdit is not the cool new editor on the block, but it is comfortable, dependable and powerful. It has some nice styling and some thoughtful features. In the end, it’s just a damn text editor, albeit a very good one.


  1. For a discussion of migrating from Textmate to BBEdit, hit the BBEdit Google group.  ↩

  2. This is my test footnote  ↩

  3. Yes, I know. Just like TextExpander. I think this is more powerful than TE’s implementation though. In BBEdit, the script is embedded inside the snippet.  ↩

  4. Awk’s cool too. Please don’t email me.  ↩

  5. By “full time” I mean at my Mac. I don’t use a Mac at my day job and I also do a good bit of work on my iPad and iPhone.  ↩

  6. Yes, I own Sublime Text 2. It’s the best option for Windows.  ↩

  7. See this discussion on the BBEdit groups for example. This was pretty frustrating while trying to discover the proper way to phrase the script.  ↩

blog comments powered by Disqus