Nathan Grigg

BBEdit Grammar Highlighting

In January, Gabe Weatherhead posted a great way to proofread using BBEdit. His idea is to define a custom “language” with a list of commonly confused words as the “keywords”. So just like how in Python mode BBEdit changes the color of if and else, in Grammar mode it can highlight their and there, or whatever other words you specify.

To do this, you create a plist file and save it into the Language Modules folder inside the BBEdit Application Support folder. Gabe links to his plist file in the post referenced above.

Highlight regular expression matches

You can take this idea one step further. A language module can use a regular expression to define what a “string” should look like. This gives you a lot of flexibility. For example, you can use this to highlight all duplicate words in the document.

Screenshot with duplicate word colored red

Here is the regular expression that matches duplicate words. You put this into the language module plist as the String Pattern.

\b(?P<dupe>\w+)\s+(?P=dupe)\b

The \b is a word anchor, and matches at the beginning or end of a word. Then (?P<dupe>\w+) finds one or more word characters and captures them to the dupe register. Next, \s+ looks for one or more whitespace characters. Finally, (?P=dupe) looks for the contents of the dupe register. The final \b ensures the end of the match is at the end of a word.

BBEdit lets you customize the color scheme for each different language. So even though my strings are usually green, I made them red for the Grammar language.

Here is the language module I use: Grammar.plist.