IntelliJ IDEA find matching parenthesis / bracket

15,875

Solution 1

use CTRL-W to expand the selection within a bracket, use repeatedly if needed to select further out, then use the arrows.

Solution 2

  • You can use Ctrl + [ and Ctrl + ] to navigate to a code block's start and end.

  • You can also use Ctrl + Shift + M to navigate between the start and end of a code block.

On Mac, you can use Option + Cmd +[ and Option + Cmd + ], and Ctrl + M


Source: https://www.jetbrains.com/help/idea/2016.2/navigating-to-braces.html

Solution 3

CTRLSHIFTM is the Windows/Linux default shortcut for action "Move caret to matched brace". (For other environments see here and use the Shortcuts dropdown in the top right of the page.)

Or if desired, the shortcut keys can be changed as follows: Go to Settings -> Keymap -> Editor Actions, or just type the name in the search box.

Solution 4

Here's the latest and greatest as of version 2020.1

To move caret between matching code block braces, press Ctrl+Shift+M.

To navigate between code blocks, press Ctrl+Shift+[ or Ctrl+Shift+].

From the documentation

Navigate with the caret

To navigate backwards, press Ctrl+Alt+← Left. To navigate forward, press Ctrl+Alt+→→ Right.

To navigate to the last edited location, press Ctrl+Shift+Backspace.

To find the current caret location in the editor, press Ctrl+M. This action might be helpful if you do not want to scroll through a large file.

However, you can press the Up and Down arrow keys to achieve the same result.

To highlight a word at the caret you are trying to locate, select Edit | Find | Next Occurrence of the Word at Caret from the main menu.

To see on what element the caret is currently positioned, press Alt+Q.

To move caret between matching code block braces, press Ctrl+Shift+M.

To navigate between code blocks, press Ctrl+Shift+[ or Ctrl+Shift+].

To move the caret forward to the next paragraph or backward to the previous one, press Ctrl+Shift+A and search for the Move Caret Forward a Paragraph or Move Caret Backward a Paragraph action.

You can also select a text and then move the caret forward or backward to a paragraph. Press Ctrl+Shift+[ and search for the Move Caret Forward a Paragraph with Selection or Move Caret Backward a Paragraph with Selection action.

Share:
15,875

Related videos on Youtube

caponica
Author by

caponica

Updated on June 17, 2022

Comments

  • caponica
    caponica almost 2 years

    Is there any keyboard shortcut to navigate from one parenthesis ( to the matching one ) in IntelliJ?

    Or even to "jump to the next opening/closing parenthesis (/) from wherever my cursor is"?

    And, if there's no way to do it 'natively', are there any plugins that could add this functionality quickly and easily?

    EDIT: the best solution I've found is added as a comment in liango's answer below, namely to put the cursor on the first or last brace and then press CTRL-W twice. Not ideal, but it does the job!

    • LazyOne
      LazyOne about 10 years
      There is no built in functionality for that, AFAIK. But you could try AceJump and emacsIDEAs plugins. What they offer is not "direct" jump .. but some advanced stuff .. which may not be suitable for you (too "advanced" -- with AceJump it's like "Ctrl+;" then ")" and then what ")" you want to jump to -- 3 keys in total).
    • caponica
      caponica about 10 years
      Thanks for this - I'll give AceJump a whirl and see how it goes. If anybody else has any suggestions for alternatives please do share.
    • lena
      lena about 10 years
      please also vote for IDEA-12068
    • UserOfStackOverFlow
      UserOfStackOverFlow about 2 years
      One of the most useful questions here on this website.
  • caponica
    caponica almost 10 years
    That's an interesting hack to get there - thanks for sharing. (I need to find a new mapping for it, though.. CTRL-W is 'close document' in my set up)
  • caponica
    caponica over 9 years
    I'm trying to get matched parentheses () not braces {} :)
  • caponica
    caponica over 9 years
    This is incorrect - as stated above, I'm trying to jump between (...) not {...}
  • caponica
    caponica almost 9 years
    Best solution I've found: put the cursor on the first/last brace and then press CTRL-W twice.
  • kaka
    kaka almost 8 years
    This is the correct answer. It works for all types of brackets, []{}()<>. Ctrl+Shift+M
  • caponica
    caponica over 7 years
    Thanks - this is now the correct answer (some 2 years after the question was first asked). Although, I think it's something like Ctrl + [ to go to nearest { and Ctrl + Shift + [ (which is Ctrl + {) to SELECT to the nearest {
  • Neerkoli
    Neerkoli over 7 years
    @caponica Uh yeah.. I'm sorry I've mistaken something there. You're right, Ctrl + paranthesis does not work.
  • Sterex
    Sterex almost 7 years
    On Mac, you can use Option + Cmd +[ and Option + Cmd + ], and Ctrl + M.
  • voddan
    voddan almost 5 years
    @SteveChambers IJ has ~5 keymap schemes across 3 OSs. In what environment are those the default shortcut?
  • Steve Chambers
    Steve Chambers almost 5 years
    @voddan Good point - I've modified your answer to specify the environment and provide a link for other environments.
  • Gunnar Bernstein
    Gunnar Bernstein over 4 years
    This does not work for german keyboards. You have to reassign the key to Ctrl+8 and Ctrl+9, where the brackets sit, but require Alt Gr to be pressed.
  • Noumenon
    Noumenon almost 3 years
    For Mac it's ^+M -- saved you some clicks.
  • Mikko Ohtamaa
    Mikko Ohtamaa over 2 years
    I also recommend Move Cared to Code Block Start/End Code with Selection bound to shift + option + command + [ and ] on Mac by default. Also if you do not remember keyboard shortcuts you can use shift x2 to open the command palette, and Actions search section to look up actions by typing their name.