December 14, 2006

Posted by John

Tagged textmate and workflow

Older: Speeding Up Prototype's $ Function

Newer: Default Options for JavaScript Classes

Two Really Handy Textmate Shortcuts

I’ve started to use two shortcuts of Textmate quite often over the past few weeks and I have decided that collectively they might be the best two shortcuts I have come across in any editor I have used to date.

1) Star Me

“Productivity depends on being able to juggle a lot of little details in short term memory all at once. Any kind of interruption can cause these details to come crashing down. When you resume work, you can’t remember any of the details (like local variable names you were using, or where you were up to in implementing that search algorithm) and you have to keep looking these things up, which slows you down a lot until you get back up to speed.”
—By Joel Spolsky in Where do these people get their (unoriginal) ideas

How often do you switch between files or even jump to the top, bottom or middle of a single file? Often is the correct answer, at least I know I do. Like Joel mentioned above, we programmers have a lot of things we are balancing in our short term memory so anything that can help us remember where we were at is extremely beneficial.

textmate star
This is where the shortcut command-F2 comes in handy. Any line that you are on and want to bookmark, just hit command-F2 and it will star (bookmark) the line. You can then jump from star to star by pressing F2. Anytime I go searching for another piece of code and I want to make sure I don’t forget where I’m currently at, I star the line. This shortcut keeps one more thing out of my short term memory and helps me to focus on what the problem at hand was, not the line number.

2) Go To File

If you have never used command-t, then open up a Rails project in Textmate. Hit command-t and start typing the name of the file you would like to open. You should see a box along the lines of the one pictured below.

textmate go to file

This is beyond handy. Especially, when you want to check out something in the Rails source. Let’s say you want to see all the core extensions to the hash object. If you have a project open with Rails froze in the vendor folder, you can hit command-t, type ‘hash’ and hit enter. Boom, the hash.rb file is now open. From there you can see all the files that extend hash. Pick one, hit command-t again, type the name of the one you picked and hit enter. So handy.

So those are my favorite shortcuts, now it is your turn. Name one or two Textmate shortcuts you would really miss if they went away tomorrow in the comments below.

14 Comments

  1. I wasn’t aware of the bookmarking feature – nice one. As well as go to file, there is Cmd+Shift+T which is go to symbol – classes, methods etc. using a find as you type system like go to file.,

    I also went over some Ruby-related stuff in this article on my blog:
    http://lukeredpath.co.uk/2006/10/30/exploring-textmate-a-ruby-perspective

  2. Ned Baldessin Ned Baldessin

    Dec 14, 2006

    Command-Shift-R => reveals the current file in the project drawer, very useful when you open files with command-t and are working on a huge Rails project.

    My only problem with TextMate is the way the SVN GUI is integrated, or, shall we say, tacked on. The menu you get with Control-Shift-A should be integrated into a standard right-click, and the status of files should be visually be displayed in the project drawer (along with HFS+ color family metadata!).

  3. The big two are snippets and templates – I create a bundle for any large projects I’m working on, which contains a template for each page type, and any other files I create regularly.

    I recently discovered drag commands as well, which are a work of genious – drag a stylesheet into your page, and it’ll create a link to it. Drag in an image, and it’ll add an image tag with the correct dimensions.

    In short, I’d be lost without TextMate, which is the only “IDE” I’ve got on with.

  4. Maybe you know if there is something similar in Win32 IDEs, such as Eclipse or Jedit ?

  5. The ease of which one can customize TextMate is one of the big winners for me. I can write snippets and commmands in Ruby without having to learn some editor-specific config language.

  6. Andrew Skegg Andrew Skegg

    Dec 14, 2006

    There are so many useful shortcuts in Textmate I often feel I am not using the application to the fullest capacity. I just discovered “goto file” yesterday and now I have another useful shortcut. Thankyou.

    Also, I have found control-shift-d (duplicate line) very handy.

  7. ArthurGeek ArthurGeek

    Dec 14, 2006

    Cmd + Shift + & = Convert any chars to html entities. At least for me (I am Brazilian, using a lot of entities in the views)is the most useful and the most one i mess on others editors. :)

  8. @Luke – Yeah, great article. I’ve read it a few times.

    @Ned – command-shift-r is trying to run a focused unit test for me, even when I’m in a file like active record base.

    @Jon – wow, I didn’t know about the drag and drop, very cool.

    @Sandro – I’m unaware of anything as cool as textmate. :)

    @topfunky – so true. I haven’t tried creating ruby snippets and such but I’m amazed at how easy it is to create your own bundles.

    @Andrew – Yep, ctrl-shift-d is handy and so is it’s partner in crime ctrl-shift-j which joins the next line with the current.

  9. @John & @Ned: The ‘reveal in project’ is associated with ctrl+option+r (as per the file menu)

  10. I hate to sound like a moron, but I’m new to the Mac and Textmate. I am learning the shortcuts a little at a time. I’ve found that I really need the shortcut to go to the “alternate file”. It shows it as , but that doesn’t do anything on my Macbook keyboard. Am I missing something?

  11. John, the Command-T feature is not only very handy but it is even ‘adaptive’ because it learns from your previous searches.

    By typing e.g. ‘p1r’ Textmate finds files called e.g. ‘part1test.rhtml’, you can check this out yourself by typing a few characters in your own project. Notice how Textmate makes matching characters bold.

    If you select a file based on such a shortcut, the next time Textmate will place the selected file on top of the result list. Just hit enter and the file is loaded.

  12. @Tom – Hmm…no nothing special. Odd. I have used it before and it worked fine. Not sure what is up.

    @Erik – I have noticed that.

  13. I believe the reveal in project drawer is actually Ctrl-Cmd-R, no option, no shift…

  14. @Jack – Hmm…on mine it is definitely cmd-option-ctrl-d. Not to say that a newer version of textmate hasn’t changed it…

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.

Projects

Flipper
Release your software more often with fewer problems.
Flip your features.