Header
We have launched our new Privacy Policy. You can read more about it here.
Advertisement

Quick Tip: Banish Repetitive Tasks with Sublime Text 2 Macros

by

If there's one thing which can waste a lot of designers' and developers' time, it's repetitive coding. How often do you find yourself formatting and duplicating bits of code which don't really warrant making snippets from? Sublime Text 2 has just the tool to speed things up..


Watch the Tip

Alternatively, Download the video, or subscribe to Webdesigntuts+ screencasts via iTunes or YouTube!


Helpful Snippets

Here are my settings that I use at the moment. In my Default (OSX).sublime-keymap (which I open by going to Sublime Text preferences, and opening up “Key Bindings - User” ) I have the following:

Just in case you’re wondering, this is a JSON Format. In “keys” you specify what to run, and in args.file - the location of the macro file to run.

Note: “super” is the name for mac users' “Command” button. Windows and Linux users should replace this with “ctrl” and use “Control” instead of “Command”. The file would look something like this:


My Macros

If you find it helpful, here are a few of the macro files I use regularly.

Double Semicolon.sublime-macro
The “Double Semicolon” is what we created in the video (although it's pretty much useless) just so you can compare your results with mine:

New Line Array.sublime-macro
Goes to the end of line, adds in a comma (“ , “) and advances to a new line.

New Line Curly.sublime-macro
A little helper to save one keystroke; automatically adds in a curly brace, and advances to a new line with alt+enter (remember, the keyboard shortcuts aren’t set in this file, but in the preferences file.)

EOL Semicolon.sublime-macro
Adds a semicolon at the end of the current line, no matter where the cursor is.

New Line Semicolon.sublime-macro
Adds a semicolon at the end of the current line, and then advances to a new line.

Array Arrow.sublime-macro
Best explained in the Quick Tip video - a nice helper for writing PHP Arrays.

Advertisement