Expand Selection to Word

A nice idea by Dmitri Goosens on Twitter today, based on the rectangular block selection that has been a standard part of NetBeans IDE for a few releases already.

The idea with this functionality, known as "block selection" or "rectangular selection", is that you can switch on "block mode" and then select across lines and change text all at the same time:

Here you can see, I have changed "multiple" to "many" simply by selecting a block of "multiple" and then typing, just once, "many":

However, what if you want to change only some of the instances of "multiple" and what if they're not neatly lined up like above? That's the point Dmitri Goosen made on Twitter today.

So I started creating a plugin that lets the user select (by double-clicking) the words that should be changed all in one go. Right now, only the selection works, which was quite a bit of work to get right.

Below you can see that only some of the "multiple" words are selected, i.e., I created a plugin that turns any selected word/s into a specially highlighted area, not with the standard yellowy background, but by making the borders of the selected word/s blue:

When you press Escape, all the blue borders disappear, i.e., nothing is then selected anymore.

Here's the sources:


Would be great if someone would clone them and then add code for changing the selected word/s to whatever the user types. A basic implementation is as follows, where the workflow is (1) select multiple words and then (2) press F12 to popup a small dialog where you can enter the replacement text. Then (3) press OK to perform the replacement.

Inline replacement will be better, same as replacement after block selection.

This could be incredibly powerful feature in NetBeans, i.e., imagine being able to select arbitrary words in a file and change all of them at the same time.


Imagine someone actually fixing keyboard shortcuts for Netbeans find/replace dialog so we don't have to jump through such hoops in the first place?

Honestly, how can you ship an IDE where you have to use a mouse to search/replace text in the editor? This is a serious regression, for over 3 years now.


Posted by Gili on May 23, 2014 at 09:38 PM PDT #

Can you point me to the issue number please?

Posted by Geertjan on May 24, 2014 at 12:08 AM PDT #

This sounds a lot like the refactoring functionality that already works awesomely. Perhaps a ctrl+doubleClick to select words you want replaced and then just type to replace them like you do with refactoring or code templates today.

Posted by Kyle on May 24, 2014 at 09:37 PM PDT #

That's nifty work. However, I'm not sure if I didn't feel more comfortable using regular expressions for such operations (I used these similar operations back in 1981 in WordStar and later MS Word 2.0 [DOS version] - took a while to get some of these regexes right but then I always had a rollback and/or backup copy).

Posted by Darragh McCurragh on May 26, 2014 at 06:10 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« March 2015