IntelliJ Tips & Tricks
An efficient programmer should be able to navigate the working environment using keyboard shortcuts. The
mouse is slow! In this video, Neal explains why and shows you some essential tips.
This demo were shot by Neal Ford. Thanks, Neal!
Smart type completion after new
The SmartType code completion may be used after a "new" keyword to instantiate an object of the expected type. For example, type
and press Ctrl+Shift+Space:
Smart type completion
The SmartType code completion greatly helps to find methods and variables that are suitable in the current context by analyzing the expected type of the whole expression. For example, type and press Ctrl+Shift+Space:
The SmartType completion also works after "return", in an assignment, in argument list of a method call and other places.
Replace By when using lookup
When using Code Completion, you can accept the currently highlighted selection in the popup list with the Tab key.
Unlike accepting with the Enter key, the selected name will overwrite the rest of the name to the right of the caret. This can be especially useful for replacing one method or variable name with another.
Variable name completion
The CodeCompletion feature is able to suggest a name for a variable when you declare it. For example, you may start typing "private FileOutputStream" and press Ctrl+Space.
You may customize name prefixes for local variables, parameters, instance and static fields in Options | IDE Settings | Code Style.
Finish lookup by special characters
When using Code Completion, you can accept the currently highlighted selection in the popup list with the period (.) character, the comma (,), the semicolon (';'), the space and other characters. The selected name is automatically entered in the editor followed by the entered character.
Class name completion
A special variant of the CodeCompletion feature invoked by Ctrl+Alt+Space allows you to complete the name of any class no matter if it was imported in the current file or not. If the class is not imported yet the import statement is generated automatically.
Basic code completion
The CodeCompletion feature allows you to quickly complete different kinds of statements in the code. For example, you may start typing a class name and press Ctrl+Space to complete it. When multiple choices are available, they are shown in the lookup list.
Smart anonymous class instantiation
It's very easy to generate the whole anonymous implementation of some interface, for example, of some listener, by using the SmartType code completion. For example, you may type
Component component; component.addMouseListener( new <caret is here> );
and press Ctrl+Shift+Space to see what happens.
Smart type casting
When you need to cast an expression value to the required type the SmartType code completion will help you. For example, type
String s = (<caret is here>);
and press Ctrl+Shift+Space to see what happens.
Comment/Uncomment line or block
You may comment/uncomment lines and blocks of code using Ctrl+NumPad / and Ctrl+Shift+NumPad /.
Ctrl+NumPad / comments/uncomments the current line or selected block with single line comments ("//..."). Ctrl+Shift+NumPad / encloses the selected block with a block comment ("/*...*/"). To uncomment a block comment press Ctrl+Shift+NumPad / anywhere inside it.
You may easily override methods of the base class by pressing Ctrl+O (Code | Override Methods...).
To implement methods of the interfaces that the current class implements (or of the abstract base class), Ctrl+I (Code | Implement Methods...).
Quick JavaDoc in goto class or symbol
Shortcuts such as Ctrl+Q (Show Quick Javadoc), Ctrl+P (Show Parameter Info), Ctrl+B (Go to Declaration), Shift+F1 (External Javadoc) and others can be used not only in the editor, but in the code completion popup list as well.
When you want to catch exceptions thrown by some code fragment, select it in the editor, press Ctrl+Alt+T (Code | Surround with...) and choose "try/catch". It automatically generates catch blocks for all exceptions that are thrown inside the block. You may customize bodies of the generated catch blocks in Options | File Templates | Code tab. Use other items in the list to surround with other constructs.
Quick JavaDoc pop-up
To quickly see the Javadoc for the class or method used at the editor's caret, press Ctrl+Q (Show Quick Javadoc in the popup menu).
Browse external JavaDoc
To open your browser with Javadoc for the class or method used at the editor's caret, press Shift+F1 (External Javadoc in the popup menu).
You must have the path to your browser set in the "General" options (Options | IDE Settings) and paths to Javadoc-generated files added to your project (File | Project Properties) to use this feature.
Use Ctrl+Shift+Enter to complete a current statement such as if, do-while, try-catch, return (or a method call) into a syntactically correct construct.
Create property tag
You can start referring to an Ant property even if it is not defined yet. IntelliJ IDEA's intention action feature will suggest you to automatically create the necessary tag, without the need for you to leave your current editing location.
Create target tag
Refer to a non-existing target tag in your Ant-build file, and IntelliJ IDEA will suggest you to automatically create the corresponding tag. This intention action will even not make you change your current editing location.
Syntax aware selection
Ctrl+W (select word) in the editor selects a word at the caret and then selects expanding areas of the source code. For example, it may select a method name, then the expression that calls this method, then the whole statement, then the containing block, etc.
Editor incremental search
Use Alt+F3 (Search | Incremental Search) to quickly search in the editor.
Enter the word in the "Search for:" tool tip and use the arrow keys to search forward and back. Press Escape to exit.
Speed search in trees
Speed search is available in all tree-views: just start typing characters in the tree to quickly locate an item.