Geertjan's Blog

  • August 10, 2006

NetBeans Keyboard Shortcut of the Week (1)

Geertjan Wielenga
Product Manager
In the series "Learning from Others", which provides interviews with NetBeans module developers from all around the world, about their key learnings, tips and tricks, and insights into NetBeans Platform development (see the bottom of the left sidebar on http://platform.netbeans.org/), a new one, with NetBeans C/C++ Pack developer Vladimir Voskresensky, will be published soon. In the interview, when asked if he has some tips and tricks for working with NetBeans, one of his responses is:

"Another tip... it's worth it to check out the available editor shortcuts (Tools->Options->Keymap) now and then as a quick review of the features provided by the IDE! Then, select a new one to use, starting from now. Later, have a look again, and start using one more. It could significantly improve your coding."

I think this is a great tip (and he has several others, all equally practical, so be sure to read that interview when it is published on http://www.netbeans.org). So, I thought it might be cool to do exactly what Vladimir suggests, right here in this blog. Every week, I will pull a keyboard shortcut out of its relative obscurity and mention it here! Eventually, a lot of keyboard shortcuts should be covered that way. In addition, I will add the keyboard shortcut to the left sidebar in the new "Keyboard Shortcut of the Week" heading. So, to kick things off... I present to you the "Debug Identifier" shortcut. This is where you find it in the Keymap (which is part of the Options window):

In the NetBeans profile, this keyboard shortcut is mapped by default to "Ctrl + J D". This means that you first press "Ctrl + J". Once you have pressed that combination, you will see "Ctrl+J" in the IDE's status bar. Then, you press "D". This shortcut is not mapped to anything in the Eclipse and Emacs profiles, so there you'd have to do it yourself. And what does the shortcut do? Well, until 15 minutes ago, I didn't know that that shortcut even existed, but it is really pretty useful... and here's the story in 3 short pictures:

  1. Put the cursor in an identifier, like here in line 56, the cursor is inside msg:

  2. Press Ctrtl+J and then press D. I now magically, without any typing, have a brand new System.err.println in line 57, for the selected identifier:

    Not bad, right?

  3. Now, when I deploy my application, the IDE shows me the server log in the Output window and I can see the error output that the generated line 57 requested:

Pretty useful. So, whenever you want that line for free, just put the cursor in the identifier and press Ctrl+J and then press D.

So, this keyboard shortcut is the 1st keyboard shortcut of the week and has pride of place in the left sidebar of this blog, for one whole week! And in honor of that, you should use it at least once a day for the rest of the week... Next week, same day, i.e., Thursday the 17th, the 2nd keyboard shortcut of the week will be announced... feel free to propose one (per week) if you like!

Join the discussion

Comments ( 7 )
  • Gregg Sporar Thursday, August 10, 2006
    I would like to nominate Ctrl-7.
  • Adrian Milliner Saturday, August 12, 2006
    Good one. However I'd like to recommend this process is extended further.
    In IntelliJ IDEA, type soutv then tab and you get a live version of this tip with the most likely candidate being printed to stdout (in this case), but as it's live, you can modify the expression being printed.
    It's part of the Live Templates system.
    So to my point. From this tip, NB developers can discover another reason why many developers are willing to pay for IDEA over the free NB.
    NB Code Templates almost cater for this, but NB isn't smart enough to fill in the most likely expression. Eg, if I had:
    System.out.println("${expr} ="+${expr});
    bound to "soutv"
    I'd have to type in the value for expr, but just once.
  • Adrian Milliner Saturday, August 12, 2006
    Digging a bit in NB55, see that if I do a "soutv" Code Template of:

    System.out.println("${expr instanceof="java.lang.Object"} = "+${expr});

    This works almost exactly IDEA. Hurrah!

    So why isn't this documented?

  • Geertjan Saturday, August 12, 2006
    Hi Gregg, thanks for the nomination!

    Hi Adrian, cool discoveries you're making. Good to hear that the functionality you're missing was there after all. It is documented in the helpset (under the Help menu). Open the helpset and then go to Java Project Basics | Editing Source Files | Using Code Templates | Inserting Code from a Template. Near the end of that topic, you'll find a table under the heading: "Special Code Template Syntax". Check it out and see how much more you can do with them...

  • Adrian Milliner Saturday, August 12, 2006
    So it is. Thanks!
  • Krzysztof Borkowski Wednesday, August 16, 2006
    Really cool shortcut! I'm using it many times a day.

    However, it has a bug... The problem is when you have a command splited into two or more lines. It won't work properly for something like this:
    msg =
    (ObjectMessage) message;

    The result would be:
    msg =
    System.err.println("msg = " + msg);
    (ObjectMessage) message;

    It would be really nice to have it fixed!

    Best regards.
  • Geertjan Saturday, August 19, 2006
    Hi Krzysztof. Yes, I think with this keyboard shortcut you need to be careful -- the System.err.println is always created right below the selected identifier. I don't think that's a bug, but a limitation... So long as you're aware of the limitation, you should be okay. But I agree it would be nice if that limitation was removed. You can add it to Issuezilla!
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.