Home > Software design >  In IntelliJ, is there a shortcut to get variable I've already typed to be a parameter in a meth
In IntelliJ, is there a shortcut to get variable I've already typed to be a parameter in a meth

Time:12-27

Suppose I have this code:

var x = 2;
var y = x;

Then I realize that I actually wanted this:

var y = someMethod(x);

To accomplish this, first I need to position the cursor to the left of "x", then type "someMethod(", then move my cursor to the right, and then add the final ")".

What I'd love is to have a way to, say, highlight "x", and have it automatically get inserted as a parameter to whatever I start typing.

Is there something for this in IntelliJ?

CodePudding user response:

Try using Statement Completion:

  • Point the cursor before x
  • Start typing the method name
  • Select the needed variant and press Ctrl Shift Enter

CodePudding user response:

Put the cursor at the left of x, start typing the method name and wait for the autocompletion sugestions to appear (if they don't press CTRL Space), find your method in the list, select it with keyboard arrows, and press CTR SHIFT ENTER. IDEA will automatically use x as the parameter of the method.

  • Related