The right development environment can save a programmer countless hours and is like a hammer in the carpenter’s tool belt. Since my background was in Java, my preference was for large sledge hammers and my development environment of choice was the de facto Java IDE Eclipse. It has a number of amazing features like autocomplete, refactoring and hundreds of plugins for every task imaginable. It’s no secret Java requires mountains of code, but Eclipse was made to move mountains.
In the beginning, moving over to Textmate felt like I was given just paper and pencil to do my job. The truth of the matter is that IDE lovers like myself usually imagine something like Notepad when a developer mentions that all they use is a text editor to write code. This is usually what we’re thinking:
Okay that’s cute, but seriously where do you do your development? You’ve got to have some real tools somewhere. I mean they do give Eclipse away for free you know. Like free as in free beer.
While my conversion to Textmate was a bit slow, one of the first things I quickly fell in love with was their Twilight theme for color coding programming syntax.
If Twilight doesn’t quite cut it for you, I highly recommend trying out the Vibrant Ink color theme by Justin Palmer. It was nice to know that if I was going to be using something “dumb” it was at least going to look pretty. In fact, the entire application is very beautiful, which is one of the nice side-effects of working on a Mac. I also found that the details in a number of simple features like ‘Find in Project’ were really well done.
Learning Textmate’s shortcut keys went a long way to making me comfortable with the editor and speeding up my development. Shortcuts work best when they feel like a reflex. I knew it was going to take some time to undue years of habits cultivated in another environment and so I prepared myself to be patient during the process. Because Textmate has such a minimal interface, using shortcuts is actually a crucial part of executing functions and commands efficiently in the application. Here are some of my favorite shortcuts in Textmate:
Commands I’ve Committed to Memory
|Action||Shortcut Keys||Phonetic Version|
|Jump to File||⌘ T||Command T|
|Find||⌘ F||Command F|
|Find in Project||⌘ ⇧ F||Command Shift F|
|Use Selected Text in Find||⌘ E||Command E|
|Inline Find||⌃ S||Control S|
|Reveal the Current File in the Gutter||⌃ ⌘ R||Control Command R|
Commands that are Nice to Know
|Action||Shortcut Keys||Phonetic Version|
|Select Bundle Item||⌃ ⌘ T||Control Command T|
|Move to Left Tab||⌥ ⌘ ←||Option Command Left|
|Move to Right Tab||⌥ ⌘ →||Option Command Right|
|Build PHP and Show Syntax Errors||⌃ ⇧ V||Control Shift V|
For a great sheet of a lot more shortcuts, check out the Textmate manual.
Because Textmate’s API is very extensible, the plugins developed by outside parties are both varied and powerful. Two plugins that went a long way to making Textmate feel more complete to me were the Missing Drawer and SVNMate.
The Missing Drawer plugin moves the file browser out of the drawer interface and into a side bar built into the project window so that it looks like a seamless extension of the editor.
SVNMate visually displays the SVN status of files and directories in your file browser using color and shape coded icons. An integrated visual system likes this is really nice since it helps me avoid having to go back and forth with an external SVN client to see what I’m currently modifying. For a list of other plugins available for Textmate, check out the Plugin Wiki Page.
The true power of Textmate comes from its bundles. Bundles are snippets of code that help to extend the functionality of the application as you edit text. They’re usually triggered by key commands and tend to be language specific. It wasn’t until I learned about how to use and create commands and snippets, that Textmate became more than just a pretty text editor to me. Textmate has over a hundred available bundles. There’s so many that it actually helps to hide the ones you don’t use regularly using their Bundle Editor.
The genius of bundles is that they can be written in any of the major scripting languages (PHP, Python, Perl or Ruby). Developers from any language can easily extend the functionality of Textmate within minutes of learning how Bundles work. The entire Unix shell is even at your disposal, including GREP, SED and AWK, which are all right there and accessible from the text editor. Textmate also provides tons of examples so you don’t have to start from scratch. You can even view the source for the built-in bundles right in their Bundle Editor, although most of them seem to be written in Ruby.
A perfect example highlighting the beauty of bundles is the TODO bundle. A commonly excepted comment in the programming world is TODO, which notes tasks that still need to be done.
/* TODO - Escape all output from this function. */
Development environments then take all of those comments, and combine them into one todo list with clickable links back to the code. This is great, but since the TODO comment is so common, a lot of third party libraries use it generously throughout their code, which means your nice list has 100’s of items that you will never touch. To solve this, just go to the TODO bundle and select preferences. You can ignore TODO, and make your own such as ALEXTODO, TIMTODO and RYANTODO. Then, in your code place:
/* ALEXTODO - Escape all output from this function. RYANTODO - Implement error handling. */
This will provide us with two todo lists, separated by developer, and with no todo items from third party libraries.
While this isn’t earth shattering, it is pretty convenient. Thanks to the simplicity of the bundle system, it allowed us to tweak the source code to meet our specific needs with little hassle. In comparison to Eclipse, extending Textmate is a breeze.
So far, I’ve written a shell command that opens my SVN client, SVNX, without leaving Textmate and a command that formats text into a PHP comment block using Wufoo’s standard format. I did it in a few minutes and they’re both written in PHP. For more information on implementing Textmate commands in PHP, I recommend Cirian Walsh’s article on the subject. You’ll want to take a look through the source, text and PHP bundles functionality. With just a few custom commands, Textmate has quickly and easily become a personalized PHP editor for me.
Right now, the possibilities with Textmate seem limitless. The simplicity of the application and the ease of its extensibility is too inviting to ignore and I’m very excited about seeing how far I can push this little editor. It’s beautiful, lightweight and speedy—attributes that weren’t associated with my old Eclipse IDE. Because Textmate has a very strong following, there’s a lot of blogs and resources covering its use. Two must reads are Circle Six and the excellently executed Textmate manual. If you still can’t get enough after that, here’s some links to help you get the most out of my new favorite environment :
- An In Depth Guide Covering The Basics of Using Textmate.
- Our favorite Textmate screencasts on html tags, text transformations and column selections.
- Textmate 2 Rumors and a Video of Codesense in action, which will only be available in Textmate 2.
- And if you’re hardcore, definitely join the Textmate discussions at irc://irc.freenode.net/##textmate.