Transpose or Why Sublime Text is a Better Text Editor Than Visual Studio
Today, I had a vision. The vision was simple. Double-click on a word, hold ctrl down and then double-click on another one. Execute a keyboard shortcut and boom, the two words are swapped.
The Set Up
Here’s a concrete scenario. I just wrote an expandAll function and now I need to write a collapseAll function.
2: this.$el.find('.folder').removeClass('folder-closed');
3: this.$el.find('.folder').addClass('folder-open');
4: }
2: this.$el.find('.folder').removeClass('folder-closed');
3: this.$el.find('.folder').addClass('folder-open');
4: }
1. Click, Delete, Type, Repeat: Way too many keystrokes, plus it’s error prone; what if I misspell something?
**2. Double-click, Cut/Copy, Paste, Delete, Clean-up: **I’ve done this more times than I care to admit! While the chances of misspelling are reduced, it is a cumbersome process.
3. A Macro: Too much work.
The Disappointment
The more I thought about this the more I became convinced that this should exist in a text editor. I was dreaming up scenarios, where I became an overnight internet sensation, introducing my great idea to the collective consciousness. The next logical thing to do was to see if this already existed.
My Visual Studio 2013 instance was already open, so I double-click on a word, held ctrl down, double-clicked again, and things went haywire. I lost my selection, clearly Visual Studio didn’t even support selecting multiple words.
The Discovery
Next up was Sublime Text. It launched and I was quickly on my way selecting random words in a code file. Then I quickly realize, I only need to select two. I did, and tried Ctrl+C/Ctrl+X followed by Ctrl+V. No luck. As a last ditch effort, I check out the Edit menu and quickly discovered transpose. I selected my two words and hit Ctrl+T.
Voila! My two words were swiftly swapped. Simple and elegant.
TL;DR
If you want to be able to select two words and swap them with one key stroke, this feature is called transpose (Ctrl+T) and Sublime Text 2 (including the upcoming Sublime Text 3) is the amazing text editor (http://www.sublimetext.com/) you’re looking for.