By josh / September 4, 2012

Sublime’s dynamic duo: Quick Add Next and Quick Skip Next

Two of Sublime Text’s more unique editing commands, Quick Add Next and Quick Skip Next, make a powerhouse duo if used together.

The first of these, Quick Add Next, is an excellent replacement for simple find-and-replace type changes, especially when you want to limit the changes to a subsection of the file.

When you select a word and invoke Quick Add Next, Sublime will highlight the next occurance of the word and insert a multi-select cursor at that point, allowing you to change both words simultaneously.

As an illustration of this command’s usefulness, let’s look at how we might take this HTML snippet and add a class name to each li element:

<ul>
  <li>The Office</li>
  <li>Fringe</li>
  <li>Touch</li>
</ul>

To perform this task, I can simply select the characters <li in the first element, then press invoke Quick Add Next twice to select the next two occurances. Once all of the elements are highlighted, I press Right Arrow to cancel the selection and type class="tv-shows".

To invoke Quick Add Next:

  1. Select the text you’d like to change.
  2. Press Command+D on Mac OSX or Ctrl+D on Windows or Linux.
    Or click Find | Quick Add Next in the application menu.

Quick Skip Next

When making multiple selections with Quick Add Next, it’s often useful to skip one or more occurances of the word you’re replacing. The Quick Skip Next allows you to jump over the next instance of the word you’re selecting.

For example, let’s say we would like to apply a CSS class to our list of TV shows to style the series that are in reruns differently from the ones that are still running:

<ul>
  <li class="shows">The Office</li>
  <li class="shows">The A Team</li>
  <li class="shows">Fringe</li>
  <li class="shows">The X Files</li>
  <li class="shows">Touch</li>
  <li class="shows">Knight Rider</li>
</ul>

Starting on the first list item, I position the cursor in the word shows, then invoke Quick Add Next twice to highlight the class name and move down a line, then Quick Skip Next twice, then invoke Quick Add Next, then Quick Skip Next, resulting in the following selection:

**Quick Add Next** and **Quick Skip Next** work together

The name Quick Skip Next is a little misleading. A better name might just be Quick Skip. When I started playing with this feature, I expected that highlighting a match and then invoking Quick Skip Next would immediately skip the second item and highlight the third. Instead, what happens is that Sublime unhighlights the current line and jumps to the next match. Once I understood this it was simple to make the selections I was after.

To invoke Quick Skip Next:

  1. Invoke Quick Add Next until you’ve highlighted an instance of the word that you want to skip.
  2. Press Command+K, Command+D on Mac OSX or Ctrl+K, Ctrl+D on Windows or Linux.

Learn ’em, love em.’

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

josh

Click here to add a comment

Leave a comment: