400

What is the keyboard short cut in Eclipse to jump to the closing brace of a scope?

ninesided
  • 23,085
  • 14
  • 83
  • 107
Trastle
  • 5,155
  • 6
  • 26
  • 20
  • 39
    As a bonus you can also press ALT + Shift + UP to select everything between those brackets. – RafaelLopes Sep 20 '12 at 19:11
  • the above short cut is useful, even though a bit long, which you can still customize yourself ~~ – Jackie Mar 06 '13 at 07:40
  • 3
    @RafaelLopes As per [@romaintaz's answer](http://stackoverflow.com/a/1637242/446921), you can accomplish the same thing by double clicking. In fact, it seems like `alt + shift + up` is universally equivalent to double clicking at the cursor's location, according to my brief experimentation. – Muhd Feb 21 '14 at 00:10
  • 2
    In the HTML editor `ALT + Shift + UP` keeps expanding the selection as you keep pressing it and `ALT + Shift + DOWN` contracts it. Combine that with `ALT + UP/DOWN` to move the code around = very handy. – Daniel Sokolowski Jul 15 '15 at 18:06
  • @Muhd, double clicking is not exactly the same as it excludes the braces – Christophe Roussy Jun 30 '16 at 07:21

7 Answers7

519

Place the cursor next to an opening or closing brace and punch Ctrl + Shift + P to find the matching brace. If Eclipse can't find one you'll get a "No matching bracket found" message.

edit: as mentioned by Romaintaz below, you can also get Eclipse to auto-select all of the code between two curly braces simply by double-clicking to the immediate right of a opening brace.

Abdull
  • 26,371
  • 26
  • 130
  • 172
ninesided
  • 23,085
  • 14
  • 83
  • 107
  • 21
    The same accelerator also works for matching parens () and square brackets []. – kevinarpe May 31 '11 at 08:44
  • Is there a way to select up to matching brace? Visual Studio does this using Ctrl+Shift+] (Ctrl+] means match brace; Shift means select; so Ctrl+Shift+] means select to matching brace... ) – Agnel Kurian Oct 23 '11 at 18:34
  • 4
    @AgnelKurian - If you look at @Romaintaz's answer below, you will note "that a double-click to the immediate right of the `{` will select the whole code block..." – ninesided Oct 31 '11 at 07:49
  • @ninesided - Agnel wants to select from current location to end of block, not the whole; like Shift+End selects from current location to EOL. Btw, I think it's not possible (which matching would you select till? "})]" ), since Ctrl+Shift+P works with all kinds of brackets, while VS only does with braces. – TWiStErRob Aug 03 '12 at 13:05
  • It looks like this shortcut can help you find matching tags in xml, too. romaintaz's trick doesn't seem to work there though. – SilithCrowe Jul 26 '13 at 14:36
  • @ninesided - I am using Ruby DLTK plugin with eclipse kepler in Ruby perspective. In one case of ruby code, this did not work. There was something like - `describe "SomeThingNew" do...etc`. I put applied the trick to this `do`, but landed on some code instead of an `end`. As you might know, do and end are ruby's equivalent of opening and closing braces. Can you please help me to find out why ? Thanks. – Erran Morad Sep 28 '14 at 01:17
  • @ninesided In xhtml file how to move to the closing tag from the opened tag of a component? – Woody Sep 30 '14 at 04:49
  • 1
    For me this only works with JAVA. When I edit javascript code inside an JSP file, it doesn't work. – John Henckel Feb 22 '16 at 16:46
131

As the shortcut Ctrl + Shift + P has been cited, I just wanted to add a really interesting feature: just double-click to the immediate right of the {, and Eclipse will select the whole code block between the opening { and corresponding closing }. Similarly, double-click to the immediate left of the closing '}' and eclipse will select the block.

Jasper
  • 2,166
  • 4
  • 30
  • 50
Romain Linsolas
  • 79,475
  • 49
  • 202
  • 273
80

With Ctrl + Shift + L you can open the "key assist", where you can find all the shortcuts.

Jasper
  • 2,166
  • 4
  • 30
  • 50
Tobias Schulte
  • 3,765
  • 1
  • 29
  • 33
19

To select content use Alt + Shift + Up arrow

To select content up to the next wrapping block press this shortcut again

To go back one step press Alt + Shift + Down arrow. This is also a useful shortcut when you need to select content in a complex expression and do not want to miss something.

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
19

On the Macintosh, place the cursor after either the opening or closing curly brace } and use the keys: Shift + Command + P.

Jasper
  • 2,166
  • 4
  • 30
  • 50
16

Press Ctrl + Shift + P.

Before Eclipse Juno you need to place the cursor just beyond an opening or closing brace.

In Juno cursor can be anywhere in the code block.

mmm
  • 1,688
  • 16
  • 35
  • 2
    The steps to turn this cool feature on: Window -> Preferences -> Java -> Editor-> Bracket highlighting -> Enclosing brackets – JohnEye Aug 13 '12 at 13:50
11

I found that if the chosen perspective doesn't match the type of the current file, then "go to matching brace" doesn't work. However, changing perspectives makes it work again. So, for example, when I have a PHP file open, but, say, the Java perspective active, pressing Ctrl + Shift + P does nothing. For the same file with the PHP perspective active, pressing Ctrl + Shift + P does exactly what you'd expect and puts my cursor beside the closing brace relative to the one it started at.

Jasper
  • 2,166
  • 4
  • 30
  • 50
Vanhoy
  • 111
  • 1
  • 2