Parker Smith Software

 
 

TextMate bundle shortcuts

By Brian Webb

25 Jul 2009

When coding Ruby On Rails projects we use the OS X program TextMate. Its one of the best development environments in our opinion. The thing that makes it really awesome is it's ability to have custom "bundles" added in. A bundle allows you to add in new shortcut keys which are specific to a particular filetype and specify code shippets that get pasted into your file when you hit hit that shortcut. Even better is that you can have it place your cursor at a particular point in the snippet and you can hit tab to move to other locations.

For example. We're really picky about having clean HTML, so we always put a comment at the closing tag. In any HTML, ERB, or other template file hitting CMD + SHIFT + < pastes the following code:

1
2
3
4

<div class="">

</div><!-- end . -->

When this code is pasted in the "div" is automatically highlited, if you wanted a div just hit tab and it will highlight the "class". If not just type what you wanted, maybe a "span" tag. When you change the tag type that closing tag will automatically get changed as you type. When you have hit tab to move to the "class" if you didn't want a class attribute just type what you wanted, maybe an "id". Hitting tab a 3rd time will put the cursor inside the quotes where you can name your attribute. Thus with 4 keystrokes (minus typing 'fubar') we can get this:

1
2
3
4

<div class="fubar">

</div><!-- end .fubar -->

No Spam: 3 + 2 =