Search code examples
netbeansediting

Editing multiple lines of code in Netbeans


Is there a way to select and edit multiple rows of code in netbeans?
Visual Studio allows a similar operation where you press alt and select multiple lines using the dragging motion (left click) of mouse ?


Solution

  • 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