I recently gave an ignite-style talk about TextMate power tips, in the context of craftsmanship and tools. In the talk I only had time for a few of my favorite tips and tricks, which I’d like to share with you—plus a few more.
Projects & Opening Files
mate Quickly open files from the command line—a simple yet powerful technique. You can also use it to send output from other commands into a TextMate document. For example, take stdout and open in TextMate: ls | grep foo | mate. Or just open a file: mate foobar.txt.
Dragging files or folders to TextMate icon on the Dock creates a new project with the selected items. Running mate on a directory or set of files will make a new project in TextMate.
Cmd-t Find a file in a project quickly. Super handy if you have tons of tabs open, or files nested deep inside folders.
Cmd-Ctrl-r Reveal current file in project drawer. Great for when deep down in a nested project and you need to see the context.
Ctrl-< Make an HTML element from a word file. This is smart enough to know the self-closing tags (img, hr, br, input).
Ctrl-Shift-w Wrap selection in HTML tags. Useful for wrapping a bunch of lines with lis when making a list.
Ctrl-Shift-l Wrap text as a link, taking URL from clipboard.
Cmd-Opt-. Close an element, based on the opening tag.
Cmd-Shift-c Insert a color value from the OS X color dialog, adding it to the current document as a hexadecimal value.
Ctrl-q Format CSS, also works in other formats like HTML.
! Type an exclamation point then use the tab key to insert !important quickly.
Cmd-Opt-] Align assignments for code prettification, like in arrays or variable declarations. Select the lines you want to align, and then invoke the command.
Ctrl-Shift-' Toggle single/double quotes. For example, if your cursor is inside the quotes on the word node in code like this: array( "node" ); you would use this command to toggle to single quotes.
Ctrl-Shift-v Check syntax, also works in other formats.
Cmd-/ Comment/uncomment a line or block, also works in other formats.
Esc Complete a word based on the current document. I use this one often, especially for super-long variable names in PHP files; I just type the first few letters of the variable and hit Esc until I find a match.
Ctrl-u Convert text to uppercase. Use Ctrl-Shift-u for lowerase and Ctrl-Opt-u for title case.
F5 Sort lines in the document, with an option to remove duplicates.
Ctrl-s Inline search: keep hitting the same command to find the next result in the document.
Opt-click Select columns and edit. Multi-line editing with column selection in TextMate is pretty sweet. This functionality can save lots of time by editing multiple lines in the document at the same time. It’s hard to explain with text and a screenshot, so here’s a video example: http://macromates.com/screencasts, look for Working With Numbers & Columns.
Commands & Snippets
TextMate is at its best when you extend it with your own snippets and commands to go along with all the great ones that come bundled. For example:
utc Add a UTC time stamp in any file, using `date -u +%D\ %R` UTC as the snippet triggered when you type those letters and hit tab.
bbug Add border: 1px solid red; to a stylesheet for a quick CSS debug in a browser.
Finding commands and snippets within all the options available in TextMate can be challenging—unless you commit their shortcuts to memory. Enter one of my most-used keyboard shortcuts in TextMate (bundles are groups of commands and snippets).
Cmd-Ctrl-t Look up a bundle item, greatly useful if you forget a shortcut, or need to find something obscure. It only shows results for your current file type, but you can override it by typing in ALL CAPS.
I use this one all the time since I don’t want to memorize the shortcut for every possible command or snippet. Instead I just start typing a few words, hit this command, find what I need in the list, then apply it with Enter.
There is so much more to TextMate, of course. Macros, Subversion integration, lots of great add-ons like AckMate and ProjectPlus, and the list goes on.
At our Automattic company meetup in September Matt handed out paper copies of The Dvorak Zine, a fun, well-written treatise on why Dvorak is better than the traditional QWERTY keyboard layout. I read it on the plane ride home, played with Dvorak settings on my laptop a bit, and vowed to make the switch during my next extended time off work.
Here is the timeline from my switch.
1. September 16th, 2010: Read The Dvorak Zine.
2. November 22nd, 2010: Started practicing with Master Key during a week off from work.
3. December 3rd, 2010: Removed QWERTY from my keyboard settings.
4. December 9th, 2010: Finished Master Key Dvorak drills (set to 40 WPM goal).
For fun, here are some stats as of December 9th, 2010 based on my Master Key drill results.
My tips and recommendations: Get Master Key, add Dvorak to your keyboard settings, and practice. Then remove QWERTY from your keyboard settings and use Dvorak for everything you type. Pace yourself and be patient. Keep practicing and don’t give up.
Update December 14, 2010: My goal with learning Dvorak is to get faster and more efficient at typing than I was with QWERTY—with which I type 75 WPM with accuracy. The 40 WPM mentioned in the timeline was during drills used to learn Dvorak; that speed is not the end goal.
Update December 28, 2010: This week I passed the Master Key drills again with the speed goal set at 50 WPM. My average speed is approaching 60 WPM.
Inconsistencies [in your coding style] are jarring and require more time to read and comprehend. Consistency is such a valued quality that developers often abide by a coding standard even if they dislike the coding standard itself. —Chris Shiflett and Sean Coates
I consider following a coding standard a sure sign of a craftmanship. A craftsman knows his tools and languages well, and is consistent in his coding style. Ego and personal preference give way to consistency and best practices.
If you develop on your own, create a coding style and stick with it. There are many practical reasons to abide by code standards when developing on your own. It enforces good habits and helps avoid simple syntax bugs. It speeds up your development process by giving you structure and taking the guesswork out of naming and spacing tasks. And, possibly most importantly, it ensures your code is readable to your future self.
This is all fine and dandy when you’re the only one touching the code. When you share and collaborate with other developers, however, following a coding standard is not a choice—it is mandatory. If you develop for a platform, use the coding standards of the platform. Even if you don’t agree with the standard, you should follow it anyway so that your code is understandable and usable for other developers. Chances are the standards were put in place for very good reasons, both practical and philosophical.
To learn the coding standards for a project you work with, start by looking at other people’s code. Put the standards into practice in your own code and don’t be afraid to ask for a review from someone else. Check your code against similar structures in your software’s codebase, or popular modules, themes, and plugins for the software.
A big part of my job as Theme Wrangler at Automattic is reviewing themes. Lots of themes from lots of designers and developers. Everyone seems to have their own coding style, which makes it difficult to review code and find errors quickly. As a result I spend a lot of time cleaning up themes to match WordPress coding standards before I can even begin the actual work of reviewing and updating the theme.
For that reason code style consistency is especially important to me. It enforces best practices, produces consistent code, and speeds up development between collaborators.
Use standard syntax.
Remove extra whitespace and line endings.
Use consistent spacing and indentation.
Use human-readable labels and names.
Following are examples of specific coding standards that I follow in my everyday development.
Are you the type of person who loves to read Top 10 lists, and then link them up on Twitter ad nauseam? Do you love Smashing Magazine and the tuts+ network (psdtuts, nettuts, …)? If so, this post is for you.
My latest pet peeve involves people who post and share links to web design and development tricks and “quick hit” tutorials. What are the odds that the list or tutorial is going to help you with your current work? Also, did you actually go read the list and follow the links and do the tutorial and launch a site based on it and can you show that product to me? What did you actually learn?
The tendency toward listmania is misleading at best and damaging to the web design and development community at worst. It promotes superficial knowledge, quick fix schemes, and small-minded solutions.
If you want to do quality work and be proud of your craft, avoid these sites and lists. The quick trick can’t make you a better web craftsman or -woman. There isn’t a shortcut or quick fix to learning web design and development fundamentals.
Instead spend time actually making awesome sites yourself. Build something and launch it to the public. Go to An Event Apart. Learn by doing: your experience will teach you more than any top 10 list ever will. The critical thinking and solid skills will come from your hard work, not from the latest, hottest tut.1
More fuel for the fire:
Here is the thing. While it’s fun to learn the latest way to vertically center a div on a page using jQuery, HTML5 and your mom, you’re wasting your time. You may use that what, 1-2% of the time in your projects. Your fundamentals are what is important. Positioning, layouts, typography, spacing, etc. Master those things. Tricks are just tricks. Fundamentals win the game. —Noah Stokes
One can only really learn by doing, by making mistakes, and not by following someone else’s abridged instructions. The tips might get you a quick ‘n’ dirty result, but after that, you’re none the wiser and will need more hints to get you through the next problem. To anyone with genuine aspirations to be great and to really improve themselves, drop the ridiculous lists of quick fixes and shortcuts and start learning for yourself by doing and by making mistakes. —Contrast blog
There is a “quick hit” culture amongst net junkies, where they read the bare minimum and foolishly believe they’re getting value or insight. These are the same people who bookmark links “to read later” but never do, and order piles of amazon books to sit on shelves forever. Someone thinking they’re getting value of 10 sentences along the lines of “Launch early, launch often” or “Your brand is beyond your control” is in need of far more than a top 10 list in my opinion. —commenter on the same Contrast post
1 And, this is silly, but I hate the word “tut” so much. Argh! ↩