TextMate’s Many Key Shortcuts
I have previously posted about cheat sheets and recently saw a new cheat sheet plus this nice idea of making a desktop background with TextMate shortcuts, so I decided to write a post with a few tips related to finding TextMate functionality, conventions, and the modifier glyphs.
Two common problems users run into related to key bindings are:
↩) is not enter (
⌅) — Some actions will show
⌅as the glyph, for example the button used in the commit window (for Subversion etc.).
The enter key is part of the numeric keypad on external keyboards. Laptop keyboards generally have a dedicated key for enter, though it can also be reached by using
The menu glyph is not the key — When a glyph is shown in the menu then you need to press the keys required to generate that glyph. For example if the menu shows
⌃<(control less-than) then on a US keyboard layout, where you would normally press
⇧,(shift comma) to insert a less-than character, the full key sequence becomes
⌃⇧,(control shift comma).
This also means that a key equivalent like
⌘[requires you to actually press
⌥⌘8on many european keyboards, which conflicts with the key to turn Zoom on/off (Universal Access). You can change the key used for zoom in System Preferences → Keyboard & Mouse → Keyboard Shortcuts (or you can use
⌥⇧⇥to Shift Left in TextMate)
A feature to be aware of when perusing the menus is that menu items can hide behind other items. Try for example to open TextMate’s File menu (in sticky mode) and press the
⌃ modifier key. You will see that a few items change their label. The item hidden beneath is a slight variation of the primary item, for example Close All Tabs is hidden behind Close Tab.
This feature is sometimes criticized because it makes things not discoverable by only looking, and TextMate makes it worse by not limiting itself to only hiding items behind a press of the
⌥ modifier key. But with an average of almost a dozen items in each menu (excluding the Bundles menu) I feel the added value in less items per menu makes up for lost usability in not having the items plainly visible — that said, some items presently hidden might become primary, and some primary items might become hidden. The goal is of course to hide what most users would anyway not use.
The Bundles menu is where all the functionality of TextMate is buried. Generally each language / task has its own bundle, but there are several bundles which offer general functionality, and in addition to looking at the bundles for the languages you use, I recommend also checking out the following bundles:
Diff — This is not
bbdiffor FileMerge (which is an oft requested feature) but rather a front-end to the
diffshell command with some interesting document sources, for example compare your document with the last saved version, or see the changes between what’s on the clipboard, and the current selection.
The latter action is useful if you somehow ended up with two versions of the same function and want to cut one of them. To ensure they are actually identical, just copy one to the clipboard, select the other, and now invoke Diff → Selection With Clipboard.
Hyperlink Helper (new) — I plan to write a separate post about this bundle, as its design is also of interest: it has commands to generate a link from the current word/selection, for example by looking it up on Google, Wikipedia, etc. or using the current URL from the clipboard. The interesting thing is that these commands use a template for the actual markup, so the same commands work in BBCode, DokuWiki, HTML, Markdown, Mediawiki, MoinMoin, reStructuredText, Textile, and TWiki. Adding templates for new markup languages is easy and can be done without editing any of the commands in the bundle (which is the neat thing about this design).
Math — If you ever need to do calculations while typing in TextMate, this is a very useful bundle. I did a screencast about the Math bundle.
Source — Functions related to working with source code, this includes commenting/un-commenting text, toggling quotation style for strings (something I never thought I’d use, but actually use roughly on a daily basis), aligning code, and more.
SQL — Although this bundle is for a language, I find it very useful to be able to execute SQL queries from scratch documents. Check out the Help file in this bundle for setup.
Having snippets (with tab triggers) for typical queries makes TextMate an even more attractive query runner.
Subversion — Not everybody knows that TextMate actually has very great subversion support (yes, you do not get to see the status of a file in the project drawer, but it basically does everything else and more :) ).
Text — This is analogous to the Source bundle, but more geared toward prose and text in general. For source code editing though there are still some very useful actions, such as duplicating the current line / selection, sorting lines, deleting current line, inserting the current date, etc. This bundle also has a semi-oft requested Word Count command.
TextMate — While this bundle is not directly for working with text, it has three very useful actions:
Paste Line / Selection Online… — This will paste a syntax highlighted version of your text to pastie and allows you to send the link to Adium, iChat, Colloquy, the clipboard, or similar. If you are behind a proxy then Mac OS X Hints recently had a tip about using Paste Online behind a proxy.
Create HTML From Document / Selection — This will generate HTML from the current document which you can use to get syntax highlight in Keynote or you can actually use Window → Show Web Preview to render it, and then hit
⌘Pto print it, to make up for TextMate’s lack of color printing. If you do this a lot, I recommend going to the bundle editor, locating this item and change its output from New Window to Show as HTML, that way, it will open directly as rendered HTML (from where you can print).
Install “Edit in TextMate”… — This will install an input manager that adds an “Edit in TextMate…” menu item to all Cocoa applications which you can invoke when editing text in a
WebView(as is used in Mail).
TODO — If you annotate your source with useful tags such as
FIXMEthen you can use the Show TODO List from this bundle to show a nice list of things you need to-do.
Xcode — If you work with Objective-C, don’t miss this crucial bundle for creating, building and running your Xcode projects, adding files to them, or quickly switch to the current project in Xcode.
Remembering all the key equivalents and tab triggers is hard, and TextMate has a nice feature to help you here. In the bundles menu is a Select Bundle Item… action with key equivalent
⌃⌘T. If you only want to learn one key equivalent, be sure to learn that one!
Basically it opens a window very similar to the Go to File… window, where you can enter a search string to quickly jump to a particular file.
The Select Bundle Item… window works in a similar way. It initially shows you all the bundle items available from the current scope, but allows you to search these, for example entering “comment” will show several functions related to commenting, e.g. Comment Line, Insert Comment Banner, Insert Block Comment, Insert Comment Header, etc.
By default only items reachable from the current scope are shown, but if you type the search string in UPPERCASE then it will search all scopes.
The window can also search your bundle items based on the key sequence you press. Click the magnifying glass and change the search criterion from “Item title” to “Key equivalent”, now pressing a key sequence will show all the items (reachable from the current scope) that matches this key sequence.
TextMate uses a lot of different modifiers and it might help remember them by understanding the conventions behind choosing modifiers for a key equivalent.
Many standard actions are offered by different bundles, for example both HTML, LaTeX, Markdown, and similar have an action for “making the selection bold” (by inserting appropriate markup) which is reached by pressing
⌘B. The list of “standard” action is given in the assorted bundles section of the manual and augmented by the bundles style guide (scroll down to Key Equivalents).
Keyboard Modifier Glyphs
Finally let me talk about the modifier glyphs in general.
The canonical ordering of the modifier glyphs is
⌃⌥⇧⌘, i.e. from lightest to heaviest glyph.
If you wonder how to easily type these glyphs then see my post about multi-stroke key bindings.
If you need a fixed width font to handle these glyphs (and many more) then I recommend the DejaVu Sans Mono font (based on Bitstream Vera Sans Mono). Mail has a tendency to switch font when rendering a glyph that is not available in the current one, so if you like to have your messages displayed using a monospace font and receive messages with fancy glyphs, then DeJaVu Sans Mono is the best choice.