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!
Alt+F3 gives a really simple way to do find and replace: Use it to select all occurrences of the current word or selection, then just start typing to replace or edit them all at once.
Select a block of lines, and then split it into many selections, one per line, using: Windows/Linux: Ctrl+Shift+L. Mac: ⇧+⌘+L.
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" }
As mentioned in Joe's comment to Hugo's answer, you can swap two selections via the Edit -> Permute Selections -> Reverse
menu item. Shuffle
won't always change the ordering as you want it to.
You can map this operation to a key by adding something like this to your Preferences -> Key Bindings – User
file, replacing f8
with a key binding of your choice:
{ "keys": ["f8"], "command": "permute_selection", "args": {"operation": "reverse"} },
Every day I'm shuffling...
Select both statements, Edit -> Permute Selections -> Shuffle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With