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.
This is the command or apple key.
The alt or option key.
The control (ctrl) key.
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 : +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:
— 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
— 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:
- + return : Moves down one line but doesn’t move characters behind the cursor position down to that new line
- + 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 : + right-arrow to select that rogue bracket.
File Navigation:
All the files opened in your drawer are accessible with a few button mashings.
- +t : opens the ‘go to file’ window. Just start typing the name of the file you want to go to and then hit return
- ++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.