How can I get rid of this auto complete suggestion...
# intellij
e
How can I get rid of this auto complete suggestion? The one with the stamp icon to the left. It is never what I want.
Alternatively, how can I make TAB select the highlighted suggestion instead of ENTER?
a
Press the up arrow to highlight the
for
entry in the list. Then click on the lightbulb in the bottom right
then you can click "disable .for template"
1
Alternatively: open settings and goto Settings | Editor | General | Postfix Completion
k
I find the .for template very useful, and don't really understand why it's never what you want, but if you don't like it you can disable it as Adam says.
e
Why use that template over
.forEach {}
?
@Adam S thank you
k
Because
for (element in collection) { ... }
has different semantics than
collection.forEach { ... }
. In the latter takes a function-type argument and the block is actually a lambda that introduces a new meaning for the identifier
it
, the
break
and
continue
statements cannot be used, etc. The plain
for
loop is much simpler: the code inside the block is just code inside the block, and not part of another function.
By the way, the Kotlin Coding Conventions guide prefers
for
loops: https://kotlinlang.org/docs/coding-conventions.html#loops