TextMate's Command Composability
For its complexity level, TextMate is the most well-designed application I’ve ever encountered. Featurewise1, it doesn’t compete with Vim2, Emacs, or Sublime Text—but the features it does implement are better designed than anywhere else.
TextMate’s design elegance is exemplified by its command composability. “Composability” here means commands can be chained together to produce cumulative effects that are logical and useful.
For example, lets say you want to change the name of the startTime
variable to startDate
in this Swift snippet:
struct ProcessInfo: Equatable {
let identifier: Int32
let startTime: NSDate
let commandPath: String
init(identifier: Int32, startTime: NSDate, commandPath: String) {
self.identifier = identifier
self.startTime = startTime
self.commandPath = commandPath
}
}
One approach you could take is the following:
- Select
startTime
. - Press
⌘E
to “Use Selection for Find”. - Press
⌘F
to bring up the “Find” dialog. - Press
⌥⌘F
to “Find All”. - Tab to the “Replace:” field.
- Enter
startDate
. - Click “Replace All”.
- Press
⌘W
to dismiss the “Find” dialog.
Here’s how TextMate’s command composability can be used accomplish the same goal in less steps, and without any annoying dialog boxes or clicking for “Replace All”3:
- Select
startTime
. - Press
⌘E
to “Use Selection for Find”. - Press
⌥⌘F
to “Find All”. - Enter
startDate
. - Enter
⇧⇧
to end multiple cursors.
Here’s what it looks like:
The key is the interpretation of ⌥⌘F
for “Find All”. When interpreting this command, TextMate considers the context, and performs the most logical action:
- The “Find” dialog is not visible.
- The find pasteboard is populated (by the
⌘E
earlier).
Choosing to initiate multiple cursors.
TextMate’s composability can be demonstrated further by performing the same commands with an active text selection. In that case, only instances of startDate
within the text selection are edited. This idea of acting on the current selection or, in the absence of a selection, the whole document, is pervasive throughout TextMate4.
Command composability is a defining trait of well-designed software—learning a piece of software is an investment, and one of the best ways an application can make the most of that investment is to amplify what you can accomplish for the same effort through command composability.
-
Autocomplete, linter integration, split windows, and ctags are the most problematic missing features. ↩︎
-
Vim deserves special attention in this post because it also excels at command composability. But Vim has far more design flaws than TextMate. I’d be surprised if anyone can read the chapter on regular expressions in Practical Vim and not come to this same conclusion. ↩︎
-
“Replace All” does have a keyboard shortcut,
⌃⌘G
, but it’s hard to remember. And frankly, OS X dialog boxes don’t work well when you want to choose any button other than the default (oresc
to dismiss). And “Replace All” is too dangerous to make the default. ↩︎ -
“Filter Through Command…” is my favorite example. ↩︎