Swapping text selections in Sublime Text 2

j6m8 picture j6m8 · May 28, 2013 · Viewed 9.4k times · Source

Forgive me if this has been asked before; I've looked around and while I can find (vague) documentation for swapping lines in Sublime Text, I can't see anything about swapping selections.

For instance, say I have the following text:

<div class="fade-black">...</div>
<div class="fade-white">...</div>

and I want to switch the colors of the two divs. So I select black and white. Now what? Is there anything built in, or should I be looking into writing an add-on myself? (I know that this particular example is relatively simple, but I have a lot of needs for this type of function in my code, and I can't simply swap lines because the content is not otherwise identical.)

Hopefully this helps some others out too -- definitely seems like a nice feature to know about!

Answer

Ivan Castellanos picture Ivan Castellanos · Jul 24, 2013

To swap two (or more) selections you need to use the transpose command, by default you can call it pressing ctrl + t (works on Sublime Text 3 too)

{ "keys": ["ctrl+t"], "command": "transpose" }