Editing multiple lines of code in Netbeans

A more flexible alternative to the Rectangular Selection has now been incorporated in Netbeans 8.2, which supports multiple cursors.

Demonstration of multiple carets

Keyboard shortcuts are listed on the Netbeans Wiki:

Description                      Windows/Linux      Mac
==============================   ================   ================
Add/remove caret                 Ctrl+Shift+Click   Cmd+Shift+Click 
Add caret for next occurence     Ctrl+J             Cmd+J   
Add caret for each occurrence    Ctrl+Alt+Shift+J   Ctrl+Cmd+Shift+J    
Add caret on line above          Alt+Shift+[        Ctrl+Shift+[ or
                                                     Alt+Cmd+Up
Add caret on line below          Alt+Shift+]        Ctrl+Shift+] or
                                                     Alt+Cmd+Down   
Remove last added caret          Alt+Shift+J        Ctrl+Shift+J    
Paste over the multiple carets   Ctrl+Shift+L       Cmd+Shift+L or
                                                     Alt+Cmd+V  
Remove all extra carets          Escape             Escape

It's called rectangular selection.
It can be enabled by Crtl+Shift+R

Screenshots for steps:

Rectangular Selection

By Petr on Oct 20, 2011

If you use development build, you probably noticed that NetBeans editor added Rectangular Selection action. I don't need this functionality every day, but it can be helpful in some case. One of such case is when you need to delete line numbers in a text or code copied from a tutorial. Like on the picture below.

sample code

You can select the rectangle after pressing Rectangular Selection toggle button in the editor toolbar or pressing CTRL+SHIFT+R shortcut.

Rectangular Selection toggle button

The selection can be easily done with mouse or keyboard. When you use keyboard, just place the caret on a corner, keep down SHIFT and with the arrows keys you select what you need.

keep down SHIFT and with the arrows keys you select what you need

When the selection is done, you can easily delete all the line numbers with pressing DELETE key. Then you have to exit from the rectangle selection mode (CTRL+SHIFT+R or toggle button in the editor toolbar).

If you write a text , then the text is placed on every line in the selected area. This can be useful for example for changing access modifiers of more fields in a class at once.

If you write a text , then the text is placed on every line in the selected area


After Netbeans 8.2 release

Since Netbeans 8.2 this functionality is available out of the box. Just press Shift + Ctrl and hold it down, now left click your mouse anywhere as many times as you need to.

NetBeans Development version allows you to edit multiple lines like in Sublime Text.

Don't bother to read the answer below. You don't need to download Development release any longer.

Before Netbeans 8.2 release

Yes you can! Works exactly as in SublimeText but it is not default feature so You will have to download NetBeans development build.

enter image description here

After installation press Shift + Ctrl + Alt now left click anywhere in the code while holding Shift + Ctrl + Alt. Easy and very useful.

This is how it looks like in NetBeans:

enter image description here

See video presentation at: youtube.com/watch?v=iWejyPL5YQI

When you install new NetBeans you don't have to uninstall the old one. Just leave it be. Development build will ask you if you want to import all the plugins and presets you where using in your previous NetBeans installation.


From Netbeans Wiki: Add/Remove caret and enter multi-caret mode

Shortcut Windows/Linux:

Ctrl + Shift + Click


Shortcut Mac:

Cmd + Shift + Click