On-the-floor

On the Floor

More than 20 Textmate shortcuts I use all the time

In a Mac environment, one of the favourite text editors for development is Textmate. Some people around the office have migrated to Vim, but I'll let them address that in their own posts.

I've been finding most of these shortcuts by accident. Usually by missing a usual shortcut with an inaccurate keystroke, then sudden, unexplained magic happens.

I've also discovered quite a few while watching Railscasts. If you watch the upper right hand corner of a Textmate shot you'll usually see what sort of shortcut is used to make the magic happen.

Here's a few I use all the time:

Cmd + T : List of most recent files and quick file search

Ctrl + Shift + D : Duplicates you current line/selection

Ctrl + Shift + K : Removes the entire line the cursor is on

Ctrl + Cmd + R : Show the file you are working on in the drawer

Alt + Cmd + Down : Opens the view of the action your cursor is currently in

Ctrl + L : Inserts " => " (in an .rb file)

Cmd + ] or Cmd + [ : Indent left or right

Alt + Cmd + ] : Align assignments within a block

Cmd + / : Comments out the line/selection of code using the appropriate syntax (most of the time)

Cmd + Del : Deletes everything after the cursor

Cmd + Backspace : Deletes everything before the cursor

Tab completion

This, like terminal, works more often than not. Depending on the bundles you have installed and the extension of the file you are coding, hitting tab following some snippet of code may complete what you are doing. You can also continue to tab through the options in blocks that have more than one condition/option/variable.

Loops

Def then Tab : def method ... end

Do then Tab : do |variable| ... end

If then Tab : if condition ... end

Validations

vp then Tab : validates_presence_of :attribute, :on => :create, :message => "can't be blank"

vu then Tab : validates_uniqueness_of :attribute, :on => :create, :message => "must be unique"

vf then Tab : validates_format_of :attribute, :with => /^[\w\d]+$/, :on => :create, :message => "is invalid"

Relationships

bt then Tab : belongs_to :object, :class_name => "Object", :foreign_key => "object_id"

hm then Tab : has_many :objects, :class_name => "object", :foreign_key => "reference_id"

ho then Tab : has_one :object, :class_name => "Object", :foreign_key => "object_id"

Migrations

mcol then Tab : Provides you with the options available for column migrations

mtab then Tab : Provides you with the options available for table migrations

And finally

Ctrl + Cmd + T : To see a list of all bundle items (shortcuts) available to the file you are currently working on

DIY

You can also make your own by recording and saving a Macro. In the menu under Bundles > Macros you can:

Ctrl + CMd + M : Start recording. This will record any keystrokes you make so that you can create your own shortcuts.

Shift + Cmd + M : Replay the last recording to see how it works or just repeat the last recorded action over and over.

Alt + Cmd + M : Record the last recording and assign a shortcut to it.

There are tons of bundles and shortcuts you can add use in textmate and this is only scratching the surface. Give it a shot and see what you find.

REFERENCES: http://szeryf.wordpress.com/2010/02/15/textmate-shortcuts-you-should-be-using/

Comments

On January 28 2011 at 3:17PM jamie allen said:

Another great one that I forgot:

lorem then Tab : Inserts a string of Lorem Ipsum. Great for filler content on the fly.