Sublime Text Demo: How the F Did They Do That?

Flatiron School / 4 November 2013

The following is a guest post by Theo Vora and originally appeared on his blog. Theo is currently in the Ruby-003 class at The Flatiron School. You can follow him on Twitter here.

If you have seen the demonstration on Sublime Text 2, you might be asking…

| how the f*** did that do that??

There are 6 demonstrations in all, and I’ll break down the first 3 for you.

1. Multiple Selection

| Mac | Command D | | Win/Linux | Ctrl D |

Order of Events

  1. Double-click a variable name (len in the demo). This selects/highlights the variable.
  2. Press ⌘D for each occurence of the variable.
  3. Type away! (in the demo they typed length)
  4. When you’re done, press Esc

Why you would use this

As programmers, we’re always changing our variable names. The same variable could appear 2 times or maybe 20 times (or more) in the same file! Whatever the number, this handy shortcut will save you time in the renaming process.

2. Split into Lines

| Mac | Command Shift L | | Win/Linux | Ctrl Shift L |

Order of Events

  1. Write the days of the week on separate lines. See sample below.
  2. Select all the text. Use either your mouse or use ⌘A.
  3. Press ⌘ ⇧ L. This will split your selection into seperate lines.
  4. Press “ once. This will put quotes around each day of the week.
  5. On Mac, you can use ⌘→ to jump to the end of the line. Win/Linux can use their End key.
  6. Press , once. This will place commas at the end of every line.
  7. Mac users, press Fn Delete. This brings the days into one line. Win/Linux can use their Delete key. You want the key stroke that allows you to delete the character on the right side of the cursor.
  8. On Mac, press ⌘→. Win/Linux press End key.
  9. On Mac, press Delete to delete the last comma. Win/Linux use backspace.
  10. On Mac, press ⌘ ⇧ ← to select everything on this line. Win/Linux can use Shift Home.
  11. Press [ once. This will enclose your selection in square brackets.
  12. On Mac, press ⌘← to move the cursor to the beginning of the line. Win/Linux press Home.
  13. Type days =
  14. Done!

Why you would use this

I don’t think this use case is used in everyday programming, but the little steps between them are super powerful!

The name “Split into Lines” is a little misleading. I would call it “whatever contiguous block of text I selected, turn it into individual line selections.”

Inside of a multi-line selection, you can jump to the front or the end of each of those lines. You can even move with just left and right arrow. Play with it and be merry!

3. Command Palette

| Mac | Command Shift P | | Win/Linux | Ctrl Shift P |

Order of events

  1. Press ⌘ ⇧ P
  2. Type sspy. This will tell Sublime that the syntax is Python. Then you see syntax highlighting appear.

Why you would use this

Ok, so you can set syntax. So what?

By setting syntax in Sublime, you not only get syntax color highlighting, but you also get access to the snippets of that language. I am known to set syntax of .erb files to HTML5 just to take advantage of the HTML5 snippets.

This leads me to another point! HTML5 snippets are not a standard part of Sublime. If you have Package Control installed, you can invoke it from the Command Palette! Type in package control to see all avaiable commands.

QRCode Reader on iOS7 Previous Post Hacker Monthly Next Post