Craig
Craig

Reputation: 2376

Using Intellij to select block between parentheses () or brackets [] or curly brackets {} either with keyboard or mouse

I've started working with IntelliJ and I really like it, but there are a few features which I miss compared with Eclipse. One of which is selecting blocks between {}, (), or [] or jumping between the opening/closing of a block. For example, in eclipse if you double click just after an opening parentheses it will select everything up to the matching closing parentheses as in:

method(item1, method2(itemA), item3,
  item4, item5);

Where if you double clicked after the opening parentheses method(|, then it would select everything up to the closing parentheses, right after item5. I have discovered that IntelliJ will select method bodies when you double click, but not regions inside of parentheses and not for class bodies.

Also, in eclipse, you can jump between the end and beginning of a block by pressing Ctrl+Shift+P just after the opening/closing of the block. In IntelliJ (using eclipse key mapping), Ctrl+Shift+P simply selects everything up to the method's closing curly brace '}'. I've discovered that Ctrl+Shift+} works the way that I expect but only for curly braces {} and it also selects everything between the block be it a method or class rather than just moving the cursor.

I can tell that IntelliJ is fairly sophisticated and customizable, but I can't figure out how to duplicate this feature from Eclipse. Any assistance would be appreciated in getting this functionality to work.

Thanks in advance! Craig

Upvotes: 42

Views: 24906

Answers (5)

Mansoor Siddiqui
Mansoor Siddiqui

Reputation: 21693

If you're using the Mac OS X 10.5+ keymap, selecting the enclosing scope is option(alt) + up arrow. Pressing it repeatedly expands the selection by the next enclosing scope.

If you're using the Mac OS X keymap, this action is mapped to command+W.

Upvotes: 12

Mijo
Mijo

Reputation: 611

I am using a workaround which works pretty well. Just beside the code block you will see minimize/maximize button (which is used for code folding, the minus and the plus sign you see beside the line numbers). You will find it on minus, as the code is unfolded. Just press on the minus, the whole code block will be minimized, and in one line. Choose that line, copy it, paste it, delete it or whatever you want to do with it :)

Upvotes: 3

zeeshan
zeeshan

Reputation: 5053

In Mac, go to start of a block and do:

Command + Shift + Alt + }

or go to end of a block and do:

Command + Shift + Alt + {

In Windows do it as:

Ctrl + Shift + }

and

Ctrl + Shift + {

Upvotes: 31

JeB
JeB

Reputation: 12133

I've been using Ctrl+W, but this is very annoying as it first selects a word, then an enclosing statement, then another enclosing statement and so on. You have to press Ctrl+W just too much times.

The best way I've figured for any block selection is:

  1. Press Ctrl+{ - this will take you to the beginning of the block
  2. Press Ctrl+Shift+} - this will select the whole block from the beginning to the end.

This way you're able to select a block of any size with any amount of nested blocks with few actions.

Upvotes: 5

g-t
g-t

Reputation: 1533

One of which is selecting blocks between {}, (), or [] or jumping between the opening/closing of a block.

Let's assume you have cursor on itemA.

Ctrl+W -> selected:

itemA

Ctrl+W -> selected:

method2(itemA)

Ctrl+W -> selected:

item1, method2(itemA), item3,
                item4, item5

Ctrl+W -> selected:

method(item1, method2(itemA), item3,
                item4, item5)

And so on. After that it would select whole method, class etc. Honestly this is the shortcut which I use most frequently. Unfortunately I sometimes try to use that in other applications - each web browser closes tab by pressing Ctrl+W :)

Another thing is:

  • Ctrl + {
  • Ctrl + }

It jumps to opening / closing bracket

Upvotes: 51

Related Questions