What's so great about Block Selection Mode?

By | January 12, 2018
Questions:

Longtime Eclipse user here; I recently discovered the “Block Selection Mode” (Alt-Shift-A) that was added into Eclipse 3.5. I tried it out, it’s pretty neat–I can select a rectangle of text in my source code instead of selecting things a line at a time like I usually do.

Apparently this feature is common in other editors too, under other names like “column edit mode”, etc. A lot of people seem to really love it, but I’ve got by without for a long time.

So my question is: What kinds of things is this feature useful for?

The only one I can think of is inserting a comment characters (like // or #) in front of a chunk of text. Also, I supposed if I had a bunch of variables names that were all lined up and I wanted to change the first characters for all of them at once. But surely there’s more to it than that? I mean, when it comes to choosing an editor, this feature is apparently a deal-breaker for some people!

Answers:

I find it is very useful when working with fixed-position field data files, and you only want to select a few fields for search-replace or copy-paste. It is also good for things like this:

call_foo('A',123);
call_foo('B',143);
call_foo('C',331);
call_foo('A',113);
call_foo('R',789);

The code is all the same except for some characters in some columns. You could select a block around the second parameter and search for the line containing 113. Useful when you have more than just a few lines all together in this format.

Questions:
Answers:

A colleague of mine told me of a project where they wrote JDBC code like this:

String query =
    "select question, answer, accepted " +
    "from so_answers                   " +
    "where poster = 'Jon Skeet'        " +
    "order by upvotes                  ";

So that they could block-select the SQL in order to paste it into a database tool and run it by hand. Seems a bit barmy to me, but it evidently worked for them.

Questions:
Answers:

If you arn’t using a block cut/copy/paste operation at least four or five times a day then I would suggest you’re just doing a lot of extra typing.

Questions:
Answers:

If you are looking at a file with fixed width fields, sometimes you only want to select one column.

Leave a Reply

Your email address will not be published. Required fields are marked *