Geertjan's Blog

  • May 11, 2015

Selecting Content Between Braces with Ctrl-Shift-[

Geertjan Wielenga
Product Manager

The question of the day comes from my colleague JB Brock who asks: "Is there some key combination (shortcut) in NetBeans that allows me to jump between an opening brace and closing brace, or even better, the ability to select everything between braces? I'm working in a JSON file and want to select a full object between { } braces.  Just looking to see if there is something that could make my life a little easier as I have 105 of these little sections that I need to strip out."

Here's how to do it. Below, notice that my cursor is on line 6, right before the opening brace, which means that its closing brace is helpfully highlighted so that you know which brace is the current opening brace's closing brace:

Now I press Ctrl-Shift-[ and this is the result:

Now you can press Ctrl-C to copy the selection to the clipboard.

In the next scenario, notice that my cursor is still in line 6, this time on the other side of the opening brace:

When I press Ctrl-Shift-[ in the above scenario, the selection covers everything excluding the opening and closing brace:

Now, again, press Ctrl-C and the content above is on the clipboard.

The above works in any other kind of file, as well, e.g., in Java, JavaScript, HTML, etc., which is precisely why it is great to have an integrated development environment—everything you know from one context has the potential to seamlessly be used in another context.

Join the discussion

Comments ( 8 )
  • guest Tuesday, May 12, 2015

    Tip of the day.

  • ken ampel Tuesday, May 12, 2015

    In Netbeans on my MacBook Air, the combination above for selecting code between brackets does not work.

    What does work is Command-Shift-Left Bracket. If you first put the cursor AFTER the opening bracket on the Mac, it will select all the code BETWEEN the brackets. If you put the cursor BEFORE the opening bracket, it will INCLUDE the brackets along with the code.

    I presume this applies to all Mac's since i haven't modified any keys on my Netbeans configuration.


  • Geertjan Tuesday, May 12, 2015

    Indeed, the Ctrl key on Windows is the Command key on Mac OSX. Not sure whether that isn't obvious at this point.

  • ken ampel Wednesday, May 13, 2015

    Except that there is also a control key on the Mac, which might be confusing to some.


  • guest Wednesday, May 13, 2015

    Unfortunately this shortcut doesn't work at all on contintental European keyboards which don't have [ and ] as individual keys. They're on 8 and 9 on my German keyboard, accessible via AltGr. I found no way to perform this shortcut in NetBeans, and Ctrl+Shift+8 is already assigned (show palette window).

    Other national keyboard layouts also require AltGr for various sets of wacky coding characters -- stuff like {[]}~\@. It would be great if NetBeans had a keyboard scheme that used only typewriter characters and cursor keys, i.e. those that exist as individual keys on all Latin keyboards. There wouldn't be enough keys for all functions but there are many window switching shortcuts which strike me as redundant -- I can easily use the mouse for that.

  • Geertjan Wednesday, May 13, 2015

    So, then map a different shortcut to the action. Go to the Options window to do that.

  • guest Thursday, May 14, 2015

    I use to goto Help -> Keyboard Shortcuts Card, which opens a pdf file. But now I just goto Tools -> Options -> Keymap to find shortcuts.

    You can either search text in the Actions column or type the shortcut key --- useful to find what a key sequence does. For example, I typed Ctrl+E to goto the end of the line..., it doesn't do that. ;-)

    In this case, the user could have typed in "matching" or "brace" to find out the keystroke available.

    Two comments on this feature: (1) The "Search in Shortcuts" textbox is hard to clear, because anything you type gets taken as input. Maybe a clear field button next to it... (2) This shortcut's Action is: "Extend Selection to Matching Brace", the Shortcut is "Ctrl+Shift+OPEN_BRACKET". Isn't a brace: { and a bracket [ (a bracket has a hard k sound and hard corners).

  • guest Thursday, May 14, 2015

    This key-combo works on the contents of parentheses () as well as braces.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.