Thank God for block copy!

My heavenly father, I thank you for the lovely people at JetBrains. I thank you for gifting them with the knowledge and insight that one-size-fits-all does not apply to editors. I thank you for my early exposure to AS/400 systems with 5250 terminals. I thank you for the experience of it’s block oriented interface. I thank you for bringing at least one other RPG developer over to the JetBrains staff. How else, Lord, would such a feature as block copy have been integrated into the Intellij Idea product offerings? Heavenly father I pray that you guide other developers to the benefits of the life saving feature. I thank you once again for block copy, Amen.

No I’m not crazy and the above is a serious prayer. Idea saved my life yesterday and… Oh, I’m sorry… Hi I’m Cliff. And you’re here because I’ve summoned you from far and beyond. Today I wanna hype a little known feature called block copy. (Actually I think Idea has it labeled as column mode.) When you spend 70% of your awake hours massaging Java code like I do you learn to appreciate the finer details of your editor. You look for shortcuts at every turn. You figure out that holding Shift and hitting End, Arrow-Down, Home, Delete is a quick way to join lines. (You learn that it works in most editors and text fields too.) You learn that holding the Control key while hitting the left or right arrows jumps between whitespace boundaries or if you enable the “CamelHumps” feature, between words in an identifier with no whitespace. You take tricks like this along with a few others and figure out that refactoring a method named “writeOderEentryValues” to “writeOrderEntryValues” is as simple as Shift+F6, holding Ctrl, left arrow once to the word Oder, holding Shift along with Ctrl, right arrow once to Values, fixing the misspelling, then hitting enter. You learn to laugh at other developers that struggle without the control key and fuss with the overused find/replace dialog or worse yet, the visual hunt and peck approach.

But when you get really familiar you look deeper into your IDE’s feature set and pull out tools that nobody else even knows the meaning of. How many of you, precious readers, have noticed column mode in Idea’s edit menu? Raise your hand. Now how many of you actually know what it means? How many of you would dare experiment with an unknown feature on a whim? Hey you! The last one who raised your hand… you knocked over your coffee mug in your excitement. You’re gonna wanna wipe that spill before it reaches your blackberry sitting next to your keyboard. I digress.

Column mode transforms your editor interface into something that would resemble an old AS/400 5250 ClientAccess display. No the colors won’t turn all green and black and you won’t lose any data. But the cursor selection behavior will work like the same. Now I realize many if not most of you probably never touched an AS/400 and likely don’t know what I’m talking about but bear with me. AS/400 and 5250 is considered by many to be a legacy technology, it’s those old green screen thingies you’ll spot in factories and warehouses (and in some banks) across America. Why am I so excited over such an old fashioned idea? I’ll explain. Most of you probably know that holding the shift key while arrowin up or dow is a quick way to select multiple adjacent lines of text for changing. But what if the text you’re interested in changing is tucked in a square? To be more specific, what if you Had something like this:

assertEquals(actualValue1, expectedUrl1);
assertEquals(actualValue2, expectedUrl2);
assertEquals(actualValue3, expectedUrl3);
assertEquals(actualValue4, expectedUrl4);
assertEquals(actualValue5, expectedUrl5);

and you wanted to stop your assertion failure from reading backwards. (The expected value is supposed to be first.) You could use column mode to draw a selection box around all of the actual values and cut and past them after the expected values. You could then cut and paste the expected values and place them before the comma. The fun doesn’t stop there! (I always wanted an excuse to say, “the fun doesn’t stop there!”) Here’s another nifty trick you can do in column mode. Say you have this:

myCoolObj.setFoo(new Foo());
myCoolObj.setBar(new Bar());
myCoolObj.setFuz(new Fuz());
myCoolObj.setBaz(new Baz());

Now you want to replace all of your setters with a single setter that takes var-args.

MyCoolObj {
   setEverything(Object.. everything) { /*...*/ } 

You do so and return to the above example. In column mode you draw a slim rectangle surrounding all of the close paren-semi colons ending each line but the last one and type a comma “,”. Then draw a box around all of the “myCoolObj.setXxx(” references but the first one and hit delete. Lastly you exit out of column mode and select all of the lines and hit Ctrl+Alt+L (bringing up the format selection dialog) and hit enter. You end up with:

myCoolObj.setFoo(new Foo(), new Bar(), new Fuz(), new Baz());

Now control arrow over to the first occurrence of Foo select it holding shift, ctrl and tapping the right arrow once and type “Everything”. Done deal. I was doing these kinds of transformations all through my code the past couple of days. My examples suck but when you’re used to column mode you find all kinds of time saving shortcuts. Combine that with other tools like replace in selection, “CamelHumps” word skipping, Shift F6 renaming and the other refactoring tools and before you know it you’re ripping through code doing crazy transformations in seconds with 100% accuracy. The kind of code transformations that would typically take hours to days and leave bugs for months. Words don’t do justice to such a feature. I encourage command you to try column mode. And when you’re finished there, toy with another menu option or IDE setting that you’ve never paid attention to.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s