Digging in to TextMate

Note: This post is over a year and a half old. You may want to check later in this blog to see if there is new information.

The first time I opened TextMate was about a year ago. I opened it, edited a couple of files, looked through the options, was overwhelmed and deleted the trial. It wasn’t until about 4 months ago that I decided to give it another try. I’m now a die-hard fan (as readers of this blog already know). But I know full well that the first impression of TextMate can be intimidating, especially for self-professed non-programmers like myself. Combine a huge library of commands, shortcuts and language specific tools with an almost completely barren user interface and a first-timer can be a little overwhelmed. This article is not necessarily intended for full-on geeks or converts from BBEdit or Emacs, it’s written for people who are checking out the buzz, picked up a copy through MacHeist, or just stumbled upon it and decided to check it out. The former may find some solace here, but this is going to be a “dummy’s” guide to teaching yourself the interface and exploring the available tools, not an in-depth reference. For that, see resources like TextMate: Power Editing for the Mac by James Edward Gray II. It’s available in PDF and is a great compendium of TextMate knowledge. See below for a list of other resources that should follow this initial tutorial if you haven’t already checked them out…

I’m going to touch on, but not rewrite, some basic resources that are already available. These include:

I watched a few screencasts which were quit the tease, but left me no less confused. I’m a tactile learner, according to my school shrink… I’m starting this tutorial after the point where I stopped reading the online manual (chapters three and four) and decided to just dive in. Of course, after my own exploration I headed back to the manual and finished reading. I eventually used all of the above resources and continue to use the IRC channel and mailing list. This article is for people like me who just want to figure it out and get going but fully realize that their initial questions are only going to annoy veteran users. If you haven’t at least gotten TextMate set up, check out this tutorial and check back when you’re done… Having said that, here’s a look at how to survive your first look at TextMate.

First Step: Kill Unnecessary Bundles

Filter ListThe most overwhelming thing about your first look at TextMate is the sheer number of commands. This can be remedied: All you have to do is hide the bundles you don’t need. Go into the Bundle Editor (Bundles->Bundle Editor->Show Bundle Editor) and at the bottom click on “Filter List…”. Uncheck all of the bundles that are not of immediate interest to you. You can add them back if you need them, don’t worry. This is going to clear up your menus and help you find the commands that are actually relevant. Make sure you keep Source, Text and TextMate, as noted in the dialog. Trust the dialog.

Adding More Bundles

It seems antithetical to the previous paragraph, but if you’re looking for specific functionality, you may need a bundle that’s not included in TextMate by default. There’s a section in the manual about getting more bundles, and a link on the TextMate blog about the GetBundle bundle. There are a couple of methods for getting more bundles. The simplest is to download the GetBundle bundle and use it. However, I prefer Subversion checkout to keep things under control. Don’t combine the two. Which you choose is up to you, but stick with one or the other. Add any bundles that you need, there are quite a few available.

Let The Exploration Commence

Bundle commands are only available when you have a file open in TextMate. So open one or create a new one, either with File->New or File->New From Template.

Language Check!

Your current language will largely determine what commands are available. You need to make sure that you’ve set your file to the proper language. If you opened a pre-existing file, TextMate will generally do a good job of figuring out what it is, but it doesn’t hurt to double check. If you opened a Template, you should be fine. If you’re creating a brand new file, you definitely need to set a language. To check the document type look at the bottom status bar, to the right of the line/column number indicators and notice a grey L in a circle followed by a language name. You can click on this to pull up a menu of available languages based on your installed (and unfiltered) bundles. Select an appropriate language for your exploration. If you’re looking for Ruby commands, select one of the appropriate Ruby languages. If you’re editing HTML, choose HTML… etc. Note that php files are edited within the HTML language syntax. For the purposes of this exploration, make sure you have a window open and that you know what language it’s set to.

Quick Search for a Command

Now you want to know whether TextMate can do what you want… type ⌃-⌘-t or go to Bundles->Select Bundle Item and type part of a search term into the dialog. It will search the available bundles for related commands, snippets and macros. If, for example, you were editing an HTML file and wanted to know what options you had for quickly creating unordered lists, you would open up the Select Bundle Item dialog and type “unordered” or “list”.

Manual Digging

Sometimes you don’t know what to call a command, though, or you just want to find out more about a bundle. Before you go posting newbie questions to the list, open up the bundle editor and dig.

Bundle MenuClicking on a bundle in the left pane will show the menu items for the bundle. This is the menu that the bundle’s developer has thoughtfully arranged for you. It usually categorizes all of the commands, snippets, macros and templates into an easily navigated structure and is great for a quick overview of the bundle. The title of a command is listed on the left of the middle pane of the editor. To the right of it, in standard UI fashion, is the shortcut for it. Shortcuts in grey followed by a ⇥ are tab triggers and will execute when the preceding string is typed immediately followed by the tab key. Usually these are used to insert snippets which often have a structure that allows you to tab through and set variable options in the resulting code. Items that all have the same trigger or shortcut will present a menu when triggered that can be navigated by the keyboard or mouse to select the intended item.

Snippet EditIf you want to dig deeper and see more of what a particular item does, expand the arrow next to the bundle in the left pane and select any item from the bundle. Each type of bundle item is coded with a colored icon. Green C for commands, Purple S for Snippets, Red D for drop commands, Grey P for Preferences, Grey L for Language definitions, Orange M for Macros, Blue T for Templates. You can filter the list by pulling down the menu at the top of the list and choosing a particular type of bundle item that you’d like to explore. Click a Snippet (purple S) and take a look at it. Snippets are the easiest Bundle Item to understand.

Anatomy of a Snippet

In the main window is the text that will be inserted when the snippet is triggered. Text surrounded by a ${} or any $ followed by a number is tab-stopped and will provide a means for replacing text in the Snippet after it’s inserted. If there’s a lot of regular expression code in the Snippet you’re looking at, it’s probably using transformation, which I’m not going to cover in this article. If you’re curious, go to your edit window and trigger the Snippet to see what it does.

Activation

At the bottom of the Bundle Editor window there’s a drop down that determines the trigger type. Most snippets are tab triggered, but some have shortcuts. One confusing part of the interface is that any item can have both types of triggers simultaneously. In the tab trigger, whatever text appears in the box will trigger the command or snippet when followed immediately (no space) by a ⇥ (tab). To set or change a tab trigger, just edit that text. To set a shortcut, change the pulldown to Key Equivalent, click in the text area and press the desired shortcut combination. To clear a shortcut, press the “x” in the text area. If you don’t clear out a tab trigger or shortcut before setting the other, both will be in effect.

Scope

Below the trigger (Activation) is the Scope Selector. The scope is defined in a cascade of language definitions and works like CSS selectors. A very specific scope will keep an item from triggering in the wrong place and will also give it precedence over less specific items. You can get a general idea where a command will trigger from the existing scope selector without having to delve into the language files, with a little common sense.

Templates

You’ll also find the available Templates for a bundle in the Bundle Editor. Open one up and you’ll be able to modify it to suit your needs. The actual text that’s inserted is found inside the file that’s revealed when you drop down the arrow next to the template name.

Other Bundle Items

Commands in the Bundle Editor can use a variety of languages, including shell scripting and Ruby to accomplish just about any task (when it comes to editing code). Peek through the commands to get an idea how they work and you’ll get a feel for how extensible TextMate is. Keep in mind that a good portion of the items in the Bundle Editor came from the user community, and let that give you a warm, fuzzy feeling. Macros are just what they sound like. Language Grammars and Preference Items are a little overwhelming for the purposes of this article, but feel free to look at them in awe.

Google is Your Friend

There is an ever-growing number of people like me who write about TextMate. And if you need a specific combination, such as TextMate and ActionScript, or TextMate and Ruby on Rails, head for Google. There’s a plethora of user-contributed resources available.

Wrapping Up

Well, that’s it for a quick overview. I have no intention of delving in to the creation of bundles or advanced editing in this article. There are quite a few articles out there for such pursuits, just do a little googling! Hopefully this will serve as a reference for TextMate virgins and a jumping point for people to become long time lovers with a spectacular piece of software.

» » » » » » »
  1. Derek Punsalan 01.02.07 / 10pm

    I can wholeheartedly agree that for the first-time user, TextMate definitely does a great job of looking overly complicated due to the the abundance of preference options, bundles, and the idea of snippets. For any new users who are willing to throw in the towel for something that “looks” easier to use, don’t. Take a few minutes each day before you start working (or a longer time chunk on weekends) to explore, explore, explore. TM offers much beneath the skin which will likely improve your workflow [when understood].

  2. Soryu 01.03.07 / 7am

    Nice Article, Brett and thanks for the linkage. We really should get a TextMate Aggregator up where we can collect things like this.

  3. brett 01.03.07 / 7am

    Thanks, Soryu. I was shooting for something that falls in between your two tutorials. It wasn’t supposed to get as long as it did, though ;-).

  4. Chris Messina 01.03.07 / 11am

    This is a great introduction — especially for handling bundles. I’d actually been simply ignoring them up to now — so with shrinking my list I might finally be able to get some good use out of them!

  5. » Blog Archive » TextMate tutorial 01.03.07 / 3pm

    […] I’ve already talked about using the right tools for the right job. And TextMate is (in my opinion) the perfect text editor for web developers. If TextMate seems a bit scary at first, don’t worry! Brett Terpstra from Circle Six Design has written a great tutorial for first time users, or even for those of you who haven been holding off. […]

  6. andrewskinner[dot]name » Blog Archive » links for 2007-01-04 01.04.07 / 2am

    […] Circle Six Blog » Blog Archive » Digging in to TextMate Interesting artlicle about setting up textmate for optimal use. (tags: textmate osx mac software tutorial) […]

  7. NaturalBirthing.info » Blog Archive » Some TextMate tips and tricks 01.05.07 / 8pm

    […] I’ve previously mentioned my text editor of choice is TextMate. I’m the first to admit that I am not a power user of TextMate, since I’m a word slinger not a code monkey. Lots of TextMate’s features don’t really come into play for me, but even if one discards the many features that help developers there is still lots to sink your teeth into. This avalanche of features is sure to intimidate new users, luckily our good friends at Circle Six Design have taken it upon themselves to enlighten us to some of TextMate’s features, as well as give us the low down on how to make TextMate sing (in a metaphorical sense that is). […]

  8. Josh 01.05.07 / 11pm

    Thanks for this post. I’ve been considering the switch from trusty old TextWrangler for some time, but didn’t want to learn a new setup. Thanks to your tutorial and links, I’m all set and happy with the switch so far.

  9. Paul Stamatiou 01.06.07 / 2am

    Great article! I can definitely say I felt rather overwhelmed when I used TextMate for the first time many months ago.

  10. Circle Six Blog » Blog Archive » Digging in to TextMate : Popular Bookmarks : eConsultant 01.06.07 / 12pm

    […] Circle Six Blog » Blog Archive » Digging in to TextMate Posted in bookmarks | Trackback | del.icio.us […]

  11. Lawsy 01.06.07 / 1pm

    Hiding the bundles is probably the best thing for a new TextMate user. I have narrowed mine down to about ten bundles which I use frequently.

  12. C. Wess Daniels 01.06.07 / 4pm

    Great Article, I am one of those newbies who is on the verge of not using TM, your article helped give it another chance!

  13. Like Your Work » Blog Archive » links for 2007-01-07 01.06.07 / 6pm

    […] Circle Six Blog » Blog Archive » Digging in to TextMate (tags: textmate) […]

  14. BillSaysThis 01.06.07 / 9pm

    One thing I don’t understand is why there is no PHP template even if the PHP bundle is installed. No big deal to type <?php> but it would be good to also have the file type set correctly. I’m too new, and not enough of a programmer to understand the regexes used to generate the, say, Ruby and Perl templates so help is appreciated.

  15. links for 2007-01-07 · Lawsy.net 01.07.07 / 12am

    […] Digging in to TextMate Decent tutorial on getting started with Textmate and getting used to a few of the features. (tags: tutorial textmate howto) […]

  16. brett 01.07.07 / 5am

    @BillySaysThis
    The correct language for working in php is HTML. Use an HTML template and then type php and hit tab. If you have the php bundle installed, that will insert your php start and end tags for you.

  17. BillSaysThis 01.07.07 / 11am

    @Brett: Thanks, I see how that works now. Still it isn’t what I really want because the doctype and default headers for the type of HTML file used are inserted. Further, I would disagree that this is “the correct language” because I’ve written many PHP files that have no HTML in them at all and would like to have a pure PHP template.

  18. brett 01.07.07 / 11am

    @BillSaysThis
    I see. You can pull this off with a little editing of one template file and a couple lines in some language files… The php handling in TM does leave a little to be desired, as it does seem to concentrate on embedded PHP while handling highlighting better for non-embedded. This is currently being worked out.

  19. BillSaysThis 01.07.07 / 11am

    Brett: LOL, this was the point of my initial comment as I tried to edit an existing template for this purpose and failed.

  20. brett 01.07.07 / 11am

    What you essentially have to do is edit the HTML Language file and remove PHP as a file type (it’s in the first few lines), then add it in to the PHP Language file using the same method as the HTML Language file uses. I think that would work.

    Unfortunately you can’t have it both ways, which is a problem related to TextMate’s inability to read minds ;-).

  21. Peter Witham 01.07.07 / 12pm

    Thank you for an excellent introduction to TextMate’s power. Having only just started using the application this article really helped me understand what was in front of me!

  22. Graham English 01.08.07 / 3pm

    I just got TextMate a couple of weeks ago. It’s an amazing program. Thanks for helping me get to know it a little better.

  23. thomas gigold, Eintrag: In Textmate vergraben 01.09.07 / 2pm

    […] Ok, Ok. Das letzte Stück Mac für heute. Versprochen! Digging in to TextMate Pflichartikel für Textmate-Nutzer! ;-) Trackback: http://gigold.de/archiv/2007/01/09/in-textmate-vergraben/trackback/ […]

  24. Wordpress Theme Bundle & Tipps für TextMate » Blog » BEIER-CHRISTIAN.eu | Christian Beier 01.13.07 / 3am

    […] Ebenfalls in seinem Blog lassen sich interessante Tipps zur Benutzung von TexMate finden. […]

  25. jarango » links for 2007-01-07 01.15.07 / 12pm

    […] Digging in to TextMate Tips on how to make more efficient use of TextMate. (tags: textmate) […]

  26. Textmate �幫手 : W.C.H. LOGBOOK 01.20.07 / 11am

    […] Digging in to TextMate […]

  27. Digging in to TextMate at FactoryCity 01.23.07 / 8pm

    […] read more | digg story Tag: textmateShare This […]

  28. Allan Odgaard 02.16.07 / 2am

    For the records, it should never be necessary to edit the file types array in the language grammar (as an end user).

    The extensions listed there are advisory only, if the user manually set a “foo.phpâ€? file to use the PHP language grammar, this will stick.

  29. GramBorder 03.20.07 / 1am

    Hello

    I want to all of you know, World is mine, and yoursite good Bye

  30. morganusvitus 04.05.07 / 7am

    The site looks great ! Thanks for all your help ( past, present and future !)

  31. RaymonWazerri 04.20.07 / 4pm

    Hey,
    I love what you’e doing!
    Don’t ever change and best of luck.

    Raymon W.

  32. MaryAnne 04.26.07 / 12pm

    I’m not quite understanding what all
    this is supposed to be about?
    Must be me or something…

  33. HelloWorld 04.28.07 / 5am

    Peace people

    We love you

  34. StephenG 05.02.07 / 3pm

    Hey,
    Really nice site you got here.
    I’ll come back more often and check it out. Peace!

  35. Jason’s Weblog » TextMate Primer 05.10.07 / 11pm

    […] But I haven’t really tried it out yet. It’s very overwhelming! Then I found this blog entry that has some tips and tricks for beginner […]

  36. stephen hargrove dot com » Blog Archive » TextMate Tutorial 06.17.07 / 4am

    […] over at Circle Six, has posted an awesome TextMate tutorial. If you’re new to TextMate or a little rough around the edges, this is the tutorial to start […]

  37. pysgodpkwf 06.18.07 / 7am

    Hello! Good Site! Thanks you! igtajjshica

  38. netcom 08.08.07 / 5pm

    I am interested in the topics discussed but have been feeling a little

    intimidated by the thought of the work…

  39. JoeyBurns 08.31.07 / 6pm

    Wow, there is some really nice info here.
    I’ll definitely come back soon to see everything.
    Way to go! ;-) Joey

  40. 2 « My Weblog 12.03.07 / 8am

    […] Digging in to TextMate […]

  41. Hero 03.15.08 / 4pm
  42. Andrew Wooldridge 04.03.08 / 2pm

    Thank you so much! You made something that is potentially really overwhelming really accessible. I feel like I can finally “get” TextMate now.

Have your say

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>




Safari hates me