Search code examples
sublimetext2sublimetextsublime-text-plugin

Sublime text 2, edit multiple selections sequentially, one at a time


Here's a common scenario I find myself in quite often:

std::cout << "This is a really long line of code with a placeholder at the end: " << HERE_IT_IS << "\n";
std::cout << "This is another really long line of code with a placeholder at the end: " << HERE_IT_IS << "\n";
std::cout << "This is yet another really long line of code with a placeholder at the end: " << HERE_IT_IS << "\n";

It isn't uncommon that I have 10 - 20 of these lines where I want to replace HERE_IT_IS with 10 - 20 unique tokens (ie: a, b, c, d, ...).

Currently the way I accomplish this is to create that list somewhere else in the editor, each preceded by a unique character, select all of those unique characters with multiple selection, and copy, then select all of the HERE_IT_IS identifiers with multiple selection, and paste.

What I would love to be able to do is do multiple selection on HERE_IT_IS and then edit them one by one, pressing some hotkey combination in between each one. (ie: type a, hit hotkey to continue to next selected entity, type b, hit hotkey, type c, hit hotkey, ...).

I've searched around for something like this, but haven't found anything. Does anyone know if Sublime Text has this functionality? or if there is a plugin that does? OR how I could write a plugin that does? :)

All input on the issue is welcome. Thanks!


Solution

  • On Windows hit Alt+F3 to select similar identifiers/variables/etc.. and then run through them one at a time hitting F3. As you move through the occurrences of the identifier you can edit them individually. If you need to select multiple identifiers hit Ctrl+d and modify them at once. If you make a mistake hit Ctrl+u and undo your last selection from the list of similar identifiers/variables/etc...