I was recently listening to an episode of the popular podcast Build and Analyze where Marco Arment was discussing his experience of leaving the comfort of TextMate to test drive BBEdit for a week. The results of his experiment were similar to many others who have attempted the same feat and after that week, according to Marco, he had returned to TextMate. I once did the same experiment. A dedicated TextMate user who switched to BBEdit for no other reason than the lack of updates and BBEdit happened to be in the Mac App Store at a greatly reduced price. I jumped on the opportunity to try the legendary text editor with its newly added fullscreen, auto-save, and resume features.
The humorous part of listening to Marco describe his time with BBEdit was knowing that we shared identical opinions on all of the quirks that differentiate TextMate and BBEdit. I don’t think one is any better than the other, I just think they solve the same problem with two different methods. What features BBEdit lacks, it generally makes up for in scripting ability. It has one of the most detailed and feature-rich AppleScript dictionary I have ever seen. So as I came across quirks that I could change with AppleScript, I wrote a script for them and that is what I would like to share in this mini-series of posts. Please note these articles are intended for people that are familiar enough with BBEdit to be able to add a new script and assign a keyboard shortcut in the preferences.
Wrapping Text
The first thing that drove me absolutely crazy with BBEdit is when hitting the quotes or parentheses key while text is selected, BBEdit doesn’t wrap the text in that punctuation but instead writes over the selection.
To alleviate this issue I wrote six AppleScripts (one for each commonly wrapped punctuation) and I assigned each one a keyboard shortcut. In this situation I think the keyboard shortcut is just as important as the script itself. It has to be easy to remember and close to the position your hand is already in when typing the punctuation key. So in five of the six shortcuts I simply added the command key and it felt as natural as typing the punctuation normally. For the single quotes script I settled with the Option + Command combo because it is on the same key as the double quotes.
- Wrap in Asterisks: ⇧ + ⌘ + *
- Wrap in Backticks: ⇧ + ⌘ + `
- Wrap in Brackets: ⇧ + ⌘ + ]
- Wrap in Parentheses: ⇧ + ⌘ + )
- Wrap in Quotes: ⇧ + ⌘ + “
- Wrap in Single Quotes: ⌥ + ⌘ + ’
All six scripts are variations of the same code shown below:
Download these scripts here: Wrap Text scripts
Save these scripts to the directory: ~/Library/Application Support/BBEdit/Scripts
Commenting Entire Line
The second feature of BBEdit that bugged me was the way commenting was implemented. Most of the time when I hit the “Comment” keyboard shortcut I actually wanted to comment out the entire line; instead, BBEdit starts the comment wherever the cursor is located. I wrote a script that reads the documents source language and comments out the entire current line using the correct syntax for that language.
For the keyboard shortcut I actually changed BBEdit’s default Un/Comment Selection to ⌥ + ⌘ + / so that I could configure my script with the default combination I was already used to: ⌘ + /
The script is configured to work with but is not limited to these languages:
- Unix Shell Script
- Python
- Perl
- Ruby
- Java
- Javascript
- PHP
- Objective-C
- ANSI C
- C++
- HTML
If you don’t see the language you want it is very easy to add your own – just open the script and take a look at the code.
Download the script here: Comment Entire Line
Save these scripts to the directory: ~/Library/Application Support/BBEdit/Scripts
*Stay tuned for more posts on ways to really get the most out of BBEdit!