Code Completion Basics
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
- Smart completion
- Completion with Tab
- Statement completion
- Negating completion
- Middle matching
- Parameter info
- Quick information pop-ups
- Exclude from completion
- Completion settings
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. It means you don’t need to press any shortcuts to see suggestions. But if you want to call it explicitly, simply press Ctrl+Space.
Note, when you call Basic completion twice, it shows you more results, including private members.
Refer to the section Basic Code Completion. Completing Names and Keywords for details.
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 Ctrl+Shift+Space.
Note that when you call Smart completion twice, it shows you more results, including chains and non-imported static members.
This feature is described in the section Smart Type Code Completion. Completing Code Based on Type Information.
Completion with tab
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.
Refer to the section Using Suggestion List.
Statement completion automatically adds missing parentheses, brackets, braces and adds the necessary formatting. To complete a statement, just press Ctrl+Shift+Enter.
Refer to the section Completing Statements.
If you select a boolean item from the suggestion list with !, IntelliJ IDEA automatically adds the negation operator to the result.
Find description in the section Negating Expressions.
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. 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.
Refer to the section Viewing Method Parameter Information.
Quick information pop-ups
Quick pop-ups, such as Quick documentation (Ctrl+Q) or Quick definition (Ctrl+Shift+I), are available when you browse suggestions in code completion.
To learn how to view reference information in the suggestion lists, refer to the appropriate help section.
Exclude from 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 exclusion.
You can always turn it back in the Auto Import page of the Editor settings.
If you want to change the default settings for completion, you can do it in the Code Completion page of the Editor settings.