By josh / July 28, 2012

Selecting blocks of text with Sublime Text 2

Selecting the text inside of a set of matching parentheses, brackets or curly braces is a common text editing action for most programmers.

Using the mouse or hitting Shift+Arrow gets the job done, but it’s really clumsy. Sublime Text 2 offers a much more sophisticated tool: scoped text selection.

Scoped selection allows you to repeatedly hit a single keyboard shortcut to first select the text inside of the current set of braces or parentheses, then expand the selection out to include the next set of braces, and so on, until the entire file is selected.

Let’s look at how this works on a simple jQuery snippet.

I’ll start by placing the cursor inside of the parentheses for console.log():

Starting cursor position

The default keyboard shortcut for scoped selection is Shift+Command+Space on Mac OS X or Ctrl+Shift+Space on Windows, and invoking it selects all of the text inside of the parentheses:

First selection

Repeating the key combo expands the selection and adds the parentheses:

Second selection

I can keep walking up to wider scopes to include the curly braces for the anonymous function:

Third selection

And eventually the entire method body:

Fourth selection

P.S. Do you love using Sublime to get more done? Sign up for the free Sublime Text Tips newsletter to get more tips every week. As a bonus, I’ll send you a 12-page guide to Sublime’s advanced editing features so you can start using Sublime more effectively–today.

About the author


James King - March 10, 2013

Why did I not know this before? This is really useful to me! Does this work in the same way for PHP code?

    joshearl - March 11, 2013

    Just tested it out on a PHP snippet, and it works the same way. It selected the contents of a function defined inside a PHP tag. The next level up seems to be the PHP tag itself.

      James King - March 13, 2013

      Awesome! Thanks for the tips and I look forward to seeing more! If you ever need a Tweet shout out let me know:

Click here to add a comment

Leave a comment: