Geertjan is a DZone Zone Leader and has posted 468 posts at DZone. You can read more from them at their website. View Full User Profile

8 New & Beefed Up NetBeans Keyboard Shortcuts!

  • submit to reddit

My colleague Tom McGinn recently published 10 Time Savers in NetBeans, an excellent overview of tips that everyone using NetBeans should read.

For those of us who are keyboard oriented (i.e., we hate the mouse because it breaks our workflow), here is an appendix to Tom's article, listing the very newest keyboard shortcuts, available in NetBeans IDE 7. Most are new or changed in NetBeans IDE 7.2, while the last one is new but unchanged from NetBeans IDE 7.1. 

  1. Alt + Scroll Up/Down. Increase/decrease the font size.

    Font resizing, which was first introduced in NetBeans IDE 7.1, was initially done by holding down the Ctrl key while scrolling. However, this conflicted with other actions, as explained in issue 212484. Following discussions with the NetBeans community, the Ctrl key was changed for the Alt key, and now, when you hold down the Alt key and then scroll up/down, in any file, the font size will increase/decrease.

  2. Alt + Shift + Page Up/Down. Quickly move entire code elements, i.e., statements and class members, up or down. Take the following situation. The cursor is on the first line below; if you were to use the standard Alt + Shift + Down, only the line would be moved down, which would immediately create an error in the editor because now the class cannot be compiled anymore. However, if you use Alt + Shift + Page Down instead (i.e., Page Down instead of simply Down), the entire method will move downwards, over the method below that, and will then appear below the method that is currently below it.

    In other words, the move action now has semantic knowledge of the code being moved, as well as semantic knowledge of the code around it. A similarly semantic-aware keyboard shortcut, though not new in NetBeans IDE 7, is Alt + Shift + Period, which lets you semantically expand the selection from the currently selected word to the next level of semantic knowledge, e.g., method or class, and back again via Alt + Shift + Comma.

  3. Alt + Backspace. Quickly remove the enclosing parts of a nested statement. Put the cursor within the word "for", or "if", or "else", for example, then press Alt + Backspace and the popup below is displayed.

    Mouse down or up in the list and then press Enter to confirm.

  4. Ctrl + Shift + M. Add/remove a bookmark to/from the Bookmarks Window. As always, you can set bookmarks in your code. However, now, when you do so, the bookmarks are, in addition to being marked in the file, added to the new Bookmarks Window (available via Window | Navigating | Bookmarks). From the Bookmarks Window, you can now jump across all your files and all your projects so that you can, for example, create a task-oriented track through your projects:

    In a related change, when you now use Ctrl + Shift + Period or Ctrl + Shift + Comma, to toggle back and forward between bookmarks, this handy popup appears, listing all the bookmarks found within the Bookmarks Window:

  5. Alt + Shift + F. The "Reformat" action can now be used across multiple projects, packages, and classes, for the first time. That means that when you use the old Alt + Shift + F while multiple nodes are selected in the Projects window, all files within the selected nodes will be reformatted at the same time.

  6. Ctrl + Z. The "Undo" keyboard shortcut now applies to refactorings too, for the first time. In previous releases, you needed to use a separate action especially for undoing refactorings, which was very hidden in the Refactoring menu and therefore hard to find, and therefore not frequently used because typically you wouldn't know it existed.

  7. Ctrl + Space. Once you have pressed Ctrl-F or Ctrl-H to open the Find bar or the Search bar at the bottom of any file (not only Java source files, but also HTML files, for example), you can press Ctrl + Space which lets you use code completion within the Find field, which can be very useful to get a quick overview of the items you could be trying to find.

    In the Debugger, the same is true in the New Breakpoint dialog.

  8. Ctrl + Shift + R. Change the cursor to a block selector. Then put the cursor next to the top left of the block and Shift+Click its bottom right corner. You now have a block, which you can manipulate, e.g., move or cut or copy or delete or change all the lines within the block. Start typing while having a block selected and all the lines will change simultaneously. Applies to all file types, not only Java source files, as can be seen here:

Note: And, a final tip, if you go to the Help menu in NetBeans IDE, you'll find the updated NetBeans IDE Keyboard Shortcut Card in PDF format, ideal for printing out and hanging in a nice frame in your workspace!

Published at DZone with permission of its author, Geertjan Wielenga.


Michael Bedward replied on Mon, 2012/08/27 - 8:20pm

Thanks for these Geertjan. Keyboard afficionados rule !

Just to add a note for mac users, on my keyboard most of the above use the Cmd key rather than the Ctrl key and the following two items are a little different: 

Item 2 (move code blocks) is Shift+Fn+Ctrl+Up/Down

Item 3 (remove enclosing parts) is Ctrl+Delete


George Maggessy replied on Tue, 2012/09/18 - 11:23pm

Any chance you can show the same commands for Mac?

Peter Kirkham replied on Thu, 2012/09/20 - 4:22pm

Awesome. I love keyboard shortcuts. Once you start using them you can't go back. Some things like moving lines up and down I learned in NetBeans and then found out how to do the same in MSWord etc. However some of these like Alt-Shift-PgUp and Ctrl-Z for refactorings look so good I think it's time to upgrade from 7.0.1. Thanks for sharing.

Matt Coleman replied on Fri, 2012/11/09 - 12:30am

Ctrl + Shift + R is probably my favorite of the shortcuts next is Alt + Backspace

what to buy a graphic designer 

Cata Nic replied on Fri, 2013/09/06 - 2:32am

The accessibility via the shorcuts is very important for an application. I will test your code these days.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.