Quick Add / Edit Text with Sublime Text

Quick Add Text

When writing code sometimes, despite your best intentions, you end up with some repeated patterns and sometimes you need to quickly modify all instance of that pattern.

Here at MSC one of our favorite IDEs is Sublime Text and they have a handy tool built in that they call “Quick Add Next” which is bound to Command+D on OS X and Ctrl+D on Windows and Linux machines.

This tool allows you to quickly find all instances of what you currently have selected (repeated presses of Command+D on OS X or Ctrl+D on Windows and Linux) and then modify each of them in turn by moving your cursors with the arrow keys and then entering or deleting text.

So, for example, say you want to modify your routes file and someone wrote:

resources :access_codes, :books, :comments, :evaluations, :posts, :ratings, :reviews, :users

and you want to make it a bit easier to read rather than deal with everything inline.

First, select the pattern of “, ” with your cursor, then use Command+D (on OS X) or Ctrl+D (Windows and Linux) to select each other instance of that pattern (one at a time), then once you’ve got everything selected you move the cursor to the right (just before the next resource entry) and hit return — you’ll find that your original content now looks something like this:

resources :access_codes,

This is just one of many examples of the useful simplicity of “Quick Add Next” — it not only saves time, it also makes repetitive changes to your code that much easier. Sound off in the comments about any useful shortcuts you use!

2 Comment

  1. Jim Haungs says: Reply

    You might also want to mention that it’s really easy to overshoot and select one too many instances of the pattern. In this case, UNDO will deselect the last instance.

  2. Jason Bussard says: Reply

    That’s a great point, thanks!

Leave a Reply