Sublime Text 2 Orientation
November 23, 2012
I started using Sublime Text 2 in March after getting excited about its speed, easy package control, and good reputation. I spent some time this week going through the entire Tuts+ “Perfect Workflow in Sublime Text 2” course by Jeffrey Way and realized how much I’ve been missing. I would strongly recommend this free course whether you’re interested in Sublime Text 2 or are using it with the nagging feeling that you should level up.
I’ll sum up my favorites (old and new), but it’s seriously worth your time having Jeffrey show you each in more detail.
It’s all text
The preferences are stored and edited in JSON files. The packages are uncompressed folders that simply live neatly in Sublime’s Application Support folder. (Both of these things, by the way, make it very handy to sync everything with Dropbox.) The project-wide search returns results as a flat text file in a new tab. Sublime is all about text and the keyboard, with very little UI that requires or uses anything else. You can rely on the mouse less as you get more comfortable, without the frustration or slowdown of jumping right into the terminal for text editing.
Ditch the sidebar forever with ⌘+P
Never hunt through files and folders again, just type the name of what you’re looking for whether it’s a path, a method, or … well anything. Tack on an @ symbol to a filename and all methods will be listed so you can jump in exactly where you’d like.
Do (almost) anything with the Command Palette ⌘+⇧+P
Anything Sublime can do will be accessible here so you can stay off the mouse even if you don’t have all the shortcuts down. Change syntax on the current file, install or remove a package, access snippets or build options – really just anything. It’s Alfred, but in a text editor.
Multiple Cursors & Incremental Search
I shouldn’t admit to you, dear reader, that I was happily working away in Sublime Text 2 completely oblivious to its multiple cursors. Sure, you can ⌘+click several things manually and get a new cursor for each one. But that’s little beans.
You’ve already noticed that every time you select a word, every instance of that exact same thing is highlighted. Hit ⌘+D and the next occurrence of that word will be selected with its own cursor. Repeat until you’ve got enough of them selected, then just type to change them all at once.
But it gets better: say you want to select every occurrence of that word instead of hitting ⌘+D repeatedly. Let’s do that. Start by placing your cursor inside any given word, then hit ⌘+D once to select the word. Now hit Control+⌘+G and every occurrence will be selected with its own cursor. Simple and extremely useful.
We all know that snippets are essential time-savers, and you probably already know that Tools → New Snippet will give you a (simple) template to edit and save as a .sublime-snippet file in your User folder. Jeffrey gets into setting up GitHub Gist integration and a few other helpful pointers.
Package: Package Control
Install Will Bond’s Package Manager first, and install it now if you haven’t already. Most Sublime packages are current and available through this channel, making it an absolute must if you want package discovery/installation/update/removal to take only a few keystrokes and a few seconds.
Package: Zen Coding
Use a simple, logical shorthand to quickly generate HTML structure. It’s more compelling to see this in action, but the idea is that you can write something like
div#nav>ul>li*5>a to hit tab and get…
Obviously you can do quite more than this, and it applies to CSS authoring as well.
Package: Fetch Files and Packages
Commissioned by Tuts+, this package lets you define preset file and package shortcuts so you can get a project running quickly. Simply put, it takes a predefined URL and downloads it (extracting, if necessary) to whatever directory you specify from within Sublime. I added shortcuts for jQuery, variations of the Twitter Bootstrap, the HTML5 Boilerplate, and CodeIgniter.
Package: Fast Folder & File Creation
I’m not sure why this wasn’t built into Sublime in the first place, but the AdvancedNewFile package lets you use ⌘+⌥+N to type a folder/file path and hit return to create it. This saves having to use the standard OS GUI to save a newly-created file.
Package: Sidebar Enhancements
I started using this a while ago, but in light of my newer discoveries it’ll certainly become more trivial. Anyway, use Sidebar Enhancements to get more right-click options in your sidebar.
Package: Sublime Linter
A great package that’ll check your syntax as you write, or as you save depending on how you set it up. You may have to do a little bit more work setting up linters depending on what languages you use, but the workflow improvement is surely going to be worth it. Unless you never make typos or mistakes. In that case, please contact me because I would like to talk about hiring you for everything I ever do.
Package: Sublime + Marked
I tend to use Byword for writing posts like this in Markdown, but this part of Jeffrey’s course led me to better appreciate the build system. To me, “build” always meant compile source code into a binary executable of some kind, be it a Cocoa app or a Flash/Air program. Here, Jeffrey demonstrates how you can author your Markdown and then set up a custom build, effectively launching Marked (an inexpensive Markdown viewer) with ⌘+B to view your work in HTML.
Bonus Package: Less Compiler
After seeing Jeffrey’s Markdown+Marked screencast, it dawned on me that I should be compiling Less from Sublime. (Wipe that look off your face, it just never occurred to me okay?) Sure enough, there was a package for that: LESS-build-sublime. Do some work, ⌘+B, and compile that .less into .css. Easy.
Much of this may be review, or overly simplistic for those wizards who have mastered Sublime Text 2. This is one of those posts I’ll probably be referring back to myself, and hopefully you’ve gotten something out of it as well!
Is there something you’ve stumbled on that you can’t live without? Let me know!
Update: I forgot to mention in my original post that it was Ross Hunter’s post that kicked off my latest quest to improve my Sublime workflow, and it’s probably to his credit that I ended up spending a few hours with the Tuts+ series. Thanks Ross!