|Focused on developer productivity, IntelliJ IDEA provides powerful features for code completion. However, as there are several code completion features, it is important to learn how they work and when it’s best to use each one.|
Basic completion offers most trivial suggestions for variables, types, methods, expressions, etc. It is worth mentioning that IntellIJ IDEA provides Basic completion automatically when you start typing. This means you don’t need to press any shortcuts to see suggestions. But if you want to call it explicitly, simply press Ctrl + Space shortcut.
Note, when you call Basic completion twice, it shows you more results, including private members.
Additionally to Basic completion, IntelliJ IDEA provides Smart completion which is much more advanced and comprehensive. Smart completion is aware of the expected type and data flow and offers the option relevant to the context. To call Smart completion, press Shift + Ctrl + Space.
Note that when you call Smart completion twice, it shows you more results, including chains and non-imported static members.
If you select an item from the suggestion list by clicking Tab, it will overwrite the identifier at the caret, instead of just inserting the suggestion. This is helpful if you’re editing a part of an identifier, such as a file name.
Statement completion automatically adds missing parentheses, brackets, braces and adds the necessary formatting. To complete a statement, just press Shift + Ctrl + Enter (Shift + Cmd + Enter for Mac).
If you select a boolean item from the suggestion list with !, IntelliJ IDEA automatically adds the negation operator to the result.
IntelliJ IDEA also supports so-called Middle matching. It means that you don’t necessarily need to type an identifier from the beginning. For example, if you only remember a part of the name, just type it and IntelliJ IDEA will still find the right matches for you.
If you want to see the suggested parameters for any method or constructor, just press Ctrl + P (Cmd + P for Mac). IntelliJ IDEA shows parameter info for every overloaded method or constructor, and highlights the best match for the parameters already typed. This helps you to choose between overloaded options and compare your input with what’s expected.
Quick popups such as Quick documentation (via Ctrl + Q, or Ctrl + J for Mac) or Quick definition (via Shift + Ctrl + I, or Shift + Cmd + I for Mac) are available when you browse suggestions in code completion.
If you are fed up with some class constantly appearing in the suggestion list, IntelliJ IDEA can exclude this class or even a whole package so you never see it again. Just press Alt + Enter on an item and confirm the exclusion. You can always turn it back in Settings → Editor → Auto Import.
If you want to change the default settings for completion you can do it via Settings → Editor → Code Completion.