Getting to know TextMate | Part 1

At work, I was lucky enough to have them get me a copy of TextMate to be used for our up-coming experiments / projects with Ruby on Rails. TextMate is recommended by all the big RoR gurus and for good reason. It makes working with Rails all the more enjoyable and easy. Here’s some info on some of the things you should know about TextMate to make it worth the crazy money they charge for it.

Mac Key Notation:

It’s important to be on the same page, so here’s what all the icons you see here /everywhere mean.

key_icon_command.gif This is the command or apple key.

command The alt or option key.

key_icon_control.gif The control (ctrl) key.

key_icon_shift.gif The shift key.

Basics:

First, its a very good idea (especially in editing Rails applications) to open up a whole folder at a time, instead of single files. The great thing about TextMate is that it shows you the contents of the folder in a drawer, and you’ll be able to get to all the files in that directory via short-cut keys (as we’ll see in a bit). To open a folder, simply use the open pane to select a folder but no particular file inside that folder.

I like my drawer on the right side, but the initially, the drawer always seems to open on the left for me. To correct this

  • select View » hide project drawer
  • move the TextMate window over to the far left-hand corner of the screen
  • select: View » show project drawer

TextMate opens files as tabs in the main window. Navigating these tabs can be done easily via shortcuts. Check out the Navigation section for the details.

Top of the Window:

Hitting the ‘x’ for a tab will close this tab. This will also be the result of hitting : key_icon_command.gif+w

The circle which replaces the x on a tab indicates that the file has been modified but not saved.

Side of the Window:

Quick, go to : View » Gutter » Line Numbers
to turn on line numbering on the side. Don’t turn this off.

Bottom of the Window:

At the bottom of the window are a few fields that give you info about how you are editing the document:

picture-1.png — This indicates which ‘bundle’ package you are currently using. The bundle determines what short-cut keys are available to you as well as some other aspects of how the program functions, so its good to make sure this is correct for the file type you are using. Initially, when opening up a .rb file, TextMate sets this just to “Ruby”. If you are actually using TextMate for Rails, you’ll want to change that default. Once you change the bundle package for a particular file type, it is maintained for all files of that type

picture-2.png — This indicates what gets inserted when you hit the tab key. “Soft Tabs” indicates that its actually inserting spaces instead of tabs for indentation. Apparently 2 spaces is all the rage for Rails indenting.

Bracket Completion:

TextMate tries hard to make tedium disappear when writing code, and one spot that in which this is immediately apparent is when it starts adding closed parens / brackets / squiglies to your open ones automatically. Usually this is a good thing, but there are times when you need to get around these added brackets and not grab for the mouse. These will help:

  • key_icon_command.gif + return : Moves down one line but doesn’t move characters behind the cursor position down to that new line
  • key_icon_control.gif + f : Moves cursor to the right one position
  • Sometimes you just want one bracket, in these cases its best to be on the right-hand side of a word or hit : key_icon_shift.gif + right-arrow to select that rogue bracket.

File Navigation:

All the files opened in your drawer are accessible with a few button mashings.

  • key_icon_command.gif+t : opens the ‘go to file’ window. Just start typing the name of the file you want to go to and then hit return
  • key_icon_command.gif+key_icon_shift.gif+t : opens the ‘go to symbol’ window. This means different things for different file types, but in, for example, a Rails controller file, this will allow you to skip around the different methods (actions) in the file.

More to come:

We could write a whole blog on TextMate short-cut keys, but this will be enough for now. Next time will go into a bit of formatting and how to actually use the bundles provided.

Advertisements

One Response to Getting to know TextMate | Part 1

  1. J says:

    is there a shortcut to bracket ERb: or ?

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: