X

Geertjan's Blog

  • August 19, 2006

NetBeans Keyboard Shortcut of the Week (2)

Geertjan Wielenga
Product Manager
This week's keyboard shortcut of the week is... really cool. First, put your cursor right behind a method's open brace. That spot, right behind an open brace, is secretly a very special character. Take a look here:

The cursor is on the character right behind the method's open brace. Nothing special, right? But now look at the method's closing brace. It is pink. That only happens when the cursor is right behind a method's open brace. Or the other way round... put the cursor behind the close brace and notice that the open brace turns pink. (And not just in methods, also for if statements and for statements or anything else with an open brace and a closing brace.) Try it. Put the cursor right behind an open brace and notice that the closing brace turns pink. Only when the cursor is on that one special place—right behind the open brace—does its matching brace turn pink. Then put the cursor behind the closing brace and notice the same thing in reverse.

"Apart from the pretty color, does this actually help me in any way?" Glad you asked. While the cursor is right behind the open brace, press Ctrl-{. So, press the Ctrl key and the key on your keyboard where you find the open brace (not the close brace). What happens? The cursor magically moves to the matching close brace, while the open brace turns pink. Press the same two keys and you're back where you started. That's pretty cool for navigation around your code, right?

But... it gets better. Either while the cursor is behind the open brace or behind the close brace, press Ctrl-Shift-{. Now look what happens:

The entire content between the two braces is selected. "What good does that do me?" Good question. Maybe you're about to mess around with the code and quickly want to copy it before you do so. Now, you can very quickly select it and then do Ctrl-C and, without lifting your hands from the keyboard, you've copied a big chunk of code. Press the same three keys again and you've unselected the selected block of code between the braces.

So the keyboard shortcut of the week is Ctrl-Shift-{. In honor of the keyboard shortcut of the week, you must use it at least once a day for the rest of the week... Do you know of a cool keyboard shortcut (maybe one that isn't mapped by default, but that you mapped yourself and are finding very useful)? Send it to me at g_wielenga@yahoo.com and maybe... it will become next week's keyboard shortcut of the week.

Join the discussion

Comments ( 8 )
  • Aljoscha Rittner Saturday, August 19, 2006
    But the shortcut is so bad for german keyboard layouts. The old shortcut Ctrl+B and Crtl+Shift+B was accessible from german keybords.
    The { symbol needs an AltGr+7. Ctrl-AltGr+7 does not work. Of course, Ctrl+Shift+AltGr+7 doesn't work, too.
    I think, we need a better localization - including different shortcuts - for different keyboards.
    best regards,
    josh.
  • Geertjan Saturday, August 19, 2006
    Hi Aljoscha! I think that's a good idea. A different profile per keyboard. (In fact, it is easy to create your own profile, in the Options window.) Also, you can change the shortcut easily in the Keymap section of the Options window, go to the "Other" category and there you can change the shortcut to anything you want.
  • Gregg Sporar Saturday, August 19, 2006
    Very nice. How do you feel about Alt-Shift-S and Alt-Shift-A? Are they worthy of being shortcut of the week?
  • Iwan Eising Sunday, August 20, 2006
    Not everything is selected when you use the SHIFT variant of your keys. Try it. Get compilable code, do the trick with the SHIFT key and hit CTRL-X (cut) now compile again, you'll get a compile error. I think the closing bracket shouldn't be selected.

    Iwan

  • Geertjan Wednesday, August 23, 2006
    Gregg, I think yours is even better than this shortcut. Where is it found in the Keymap window?

    Hi Iwan, you're right. I agree it would be nice if the closing bracket were to be excluded. Will you create an issue for this?

  • Ming Fang Monday, August 28, 2006
    Intelij has a ctrl-w shortcut to intelligently select the current scope. And each time you press ctrl-w the selection widens to the enclosing scope.
    Does Netbeans also have such a feature?
  • Geertjan Monday, August 28, 2006
    Alt-Shift-S and Alt-Shift-A, pointed out by Gregg above, do that. Very cool thing too.
  • guest Saturday, September 16, 2006
    Also see: http://www.netbeans.org/issues/show_bug.cgi?id=56622
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.