Search code examples
javaintellij-ideakeyboard-shortcuts

In IntelliJ, is there a shortcut to get variable I've already typed to be a parameter in a method I want to type?


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?


Solution

  • Try using Statement Completion:

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