33

I had to move from Eclipse to Android Studio for Android development. Many features are better, several are worse. In particular I miss the jump between matching braces (opening -> closing brace and v.v.) by means of a single key sequence.

I managed to find that CTRL ] takes you from the opening brace to the closing one, CTRL [ takes you from closing to opening brace. If the wrong [ or ] symbol is used when you ara already at an opening or closing brace, then the editor jumps to the next brace of that type.

Is there any key sequence which jumps between matching braces, like Eclipse does?

geekley
  • 1,231
  • 10
  • 27
NickT
  • 23,844
  • 11
  • 78
  • 121
  • don't quite understand what you mean when you say matching braces. an example would help... – Viral Patel Jul 11 '16 at 14:42
  • 3
    It's common terminology. It means find the closing brace that matches this opening one, say. So if there's a pair of {} nested quite deeply, locate the pair that go together. See https://en.wikipedia.org/wiki/Brace_matching – NickT Jul 11 '16 at 14:56

4 Answers4

46

I think you want

  • Ctrl+}

  • Ctrl+{

these move to the open and close brackets.

You want a single combination to do both?

Use Ctrl + shift + M

Reference

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
  • I have Ctrl [ and Ctrl ] to do that but I want one keying sequence that jumps to the matching opening or closing brace as I explained in the question. – NickT Jul 11 '16 at 16:10
  • Got it... You want a single combination to do both? Use Ctrl + shift + M – Viral Patel Jul 11 '16 at 16:54
  • Note: ctrl+{} doesn't seem to work for parentheses, but the other shortcut does. – geekley Aug 29 '19 at 17:51
  • Is there a shortcut like ctrl+shift+m that also selects while moving the caret? I think VSCode allows this... ctrl+] to move back and forth, and ctrl+shift+} to select from one brace/parenthesis to the other. Can I do that in Android Studio? – geekley Aug 29 '19 at 17:56
20

If this helps anyone using Android Studio on a Mac OS X machine, to jump back and forth between matching braces or parentheses, use

control + m

or possibly

control + shift + m

Gravitoid
  • 1,294
  • 1
  • 20
  • 20
  • Do both of these commands work on Mac OS X or just `control + m` works? – Bruno Alexandre Rosa Oct 04 '17 at 12:46
  • 2
    On my Mac OS X (Sierra) with Android Studio 2.3.3 only `control + m`. Someone edited in the `control + shift + m` but that didn't work for me. I wasn't about to try to figure out all versions of Mac OS X and Android Studio to see if the person who added the `control + shift +m` was really correct. – Gravitoid Oct 05 '17 at 13:35
1

I am using Android Studio 4.2.1 and now it seems like need to use cmd + shift + m to move to matching bracket. Also, this one conflicts with one of the MacOS short cut and can be modified to ctrl + shift + m

rysv
  • 2,416
  • 7
  • 30
  • 48
-1

Single key solution
You can do it as
Go to setting->keymap find Move Caret To Matched Brace add a shortcut to it.
That shortcut will take you to the end If you are at the opening brace And at the start if you are at the ending brace.
Additional :

1. For the Windows:

 - Use <kbd>Ctrl</kbd>+<kbd>]</kbd> to move to the closing bracket.

 - Use <kbd>Ctrl</kbd>+<kbd>[</kbd> to move to the opening bracket.

For the Mac:

 - Use  <kbd>cmd</kbd> instead of <kbd>Ctrl</kbd>.

2. For the Windows:

  - Use <kbd>Ctrl</kbd>+<kbd>}</kbd> to move to the closing bracket with the code selection.

  - Use <kbd>Ctrl</kbd>+<kbd>{</kbd> to move to the opening bracket with the code selection.

 For the Mac:

   - Use  <kbd>cmd</kbd> instead of <kbd>Ctrl</kbd>.
Inzimam Tariq IT
  • 6,548
  • 8
  • 42
  • 69