Random42
Random42

Reputation: 9159

Surround with suggestions from auto-complete in Intellij?

Suppose you have the following method

void consume(List<String> list) { ...

And somewhere you have, and want to call the method from above.

String sa = "whatever";

If you type:

sa

and then put the cursor before sa and want to autocomplete

Collections.sing|sa then CTRL+Space then Enter

what you'll get is

Collections.singletonList()sa and you want Collections.singletonList(sa)

Is there a way to automatically surround the variable with what auto-complete returns?

Upvotes: 3

Views: 195

Answers (2)

Char
Char

Reputation: 955

In mac it is command + shift + enter

That will surround sa with the completed code.

That action is called complete current statement, ctr + shift + enter on windows with the default keymap.

Upvotes: 1

user65839
user65839

Reputation:

Not exactly what you're looking for, but you can get a bit closer with postfix completion. After typing sa and realizing that you want to call a method on it, you can type .parTab to put the parenthesis around it, then Home to go back to the start of the line and you can type Collections.singTab to complete the method call.

That is, I think completion works the way you want if you put the parenthesis around the argument first. I'm not aware of a better way, though I'd be fine to be proven wrong.

Upvotes: 0

Related Questions