Mastering IntelliJ IDEA: Keyboard Shortcuts and Debugging Workflows
Essential Keyboard Shortcuts for IntelliJ IDEA
Mastering the IDE's hotkeys significantly accelerates development workflows. The shortcuts are categorized by their primary function.
Fundamental Editing Operations
| Action | Shortcut |
|---|---|
| Copy selection | Ctrl + C |
| Paste clipboard | Ctrl + V |
| Cut to clipboard | Ctrl + X |
| Undo last action | Ctrl + Z |
| Redo undone action | Ctrl + Shift + Z |
| Save all modified files | Ctrl + S |
| Select entire document | Ctrl + A |
Accelerating Code Construction
- Intelligent Context Actions (
Alt + Enter): Resolves compilation errors, suggests fixes, or automatically captures the return value when placed at the end of an assignment. - Live Templates (
Ctrl + J): Lists all available code snippets. Type a prefix and pressTabto expand. - Surround With (
Ctrl + Alt + T): Wraps highlighted code blocks in constructs likeif,try-catch, orsynchronized. - Code Generation (
Alt + Insert): Opens the generation menu for constructors, getters, setters,toString(), and more. - Extract Variable (
Ctrl + Alt + V): Refactors a selected expression into a local variable. - Line Manipulation: Duplicate line (
Ctrl + D), Delete line (Ctrl + Y), Insert line above (Ctrl + Alt + Enter), Insert line below (Shift + Enter). - Statement/Line Movement: Move statement up/down (
Ctrl + Shift + ↑/↓) within a block, or move the entire line beyond method boundaries (Alt + Shift + ↑/↓). - Parameter Hints (
Ctrl + P): Displays expected arguments when invoking methods.
Refactoring and Structural Navigation
- Rename (
Shift + F6): Safely renames variables, methods, or classes across the entire project scope. - Extract Method (
Ctrl + Alt + M): Isolates selected code into a new helper function, preserving static/non-static context. - Override/Implement (
Ctrl + O/Ctrl + I): Quickly generates methods from parent classes or implemented interfaces. - Toggle Case (
Ctrl + Shift + U): Switches text between uppercase and lowercase. - Optimize Imports (
Ctrl + Alt + O): Removes unused imports and sorts packages automatically. - Navigate to Class (
Ctrl + N): Searches for any class file. Clicking a symbol withCtrlalso navigates directly. - File Structure (
Ctrl + F12): Opens a floating overlay listing all fields and methods, supporting type-ahead filtering. - Navigation History: Move backward/forward through edit locations (
Ctrl + Alt + ←/→). Switch between open editor tabs (Alt + ←/→). - Type Hierarchy (
Ctrl + H): Visualizes inheritance chains for the selected class. - Quick Documentation (
Ctrl + Q): Displays Javadoc comments inline. - UML Diagram (
Ctrl + Alt + Shift + U): Generates a visual class relationship map. - Find Implementation (
Ctrl + Alt + B): Jumps directly to the concrete definition of an interface or abstract method. - Collapse/Expand (
Ctrl + Shift + - / +): Hides or reveals all method bodies for better file overview.
Search, Replace, and Formatting
- Find in Current File (
Ctrl + F): Locates text occurrences. Navigate matches withEnter/Shift + Enter. - Find Next (
F3): Cycles through search results. - Replace (
Ctrl + R): Performs targeted or global replacements within the current file. - Find Usages (
Alt + F7): Lists every reference to a symbol. PressF3to step through each occurrence. - Global Search (
Ctrl + Shift + F): Scans the entire project or module directory for specific strings. - Cursor Positioning: Jump to line start (
Home), line end (End), or specific line number (Ctrl + G). - Code Formatting (
Ctrl + Alt + L): Applies project-defined indentation and spacing rules. - Comments: Toggle line comment (
Ctrl + /), toggle block comment (Ctrl + Shift + /). - Indentation: Shift selected lines right (
Tab) or left (Shift + Tab). - Iteration Template: Type
array.for+Enterto generate an enhancedforloop.
Customizing Keymap Preferences
IntelliJ allows full customization of hotkeys via File → Settings → Keymap. Users can search for specific actions by name or bind new combinations to existing commands. Cross-platform keymaps (e.g., macOS, Eclipse, NetBeans) are available through plugins for seamless transition.
Debugging Strategeis and Workflow
Debugging is essential when applications crash silently, produce incorrect outputs, or exhibit intermittent behavior in concurrent environments. Relying solely on print statements becomes inefficient for complex logic.
Standard Debugging Procedure
- Place Breakpoints: Click the gutter next to the target line to halt execution.
- Launch Debugger: Select
Run → Debugor click the bug icon. - Control Execution Flow: Use stepping commands to advance line-by-line.
- Inspect State: Monitor variable values, thread states, and stack frames in the Debug tool window.
Line Breakpoints
Standard breakpoints pause execution at a specific statement. Place them directly in the editor gutter.
package org.devtools.debug;
public class ArithmeticProcessor {
public static void main(String[] args) {
int baseValue = 100;
int multiplier = 5;
int result = calculateProduct(baseValue, multiplier);
System.out.println("Initial product: " + result);
// Adjust values dynamically
baseValue = 200;
result = calculateProduct(baseValue, multiplier);
System.out.println("Adjusted product: " + result);
int[] sequence = {10, 20, 30, 40, 50};
System.out.println("Sequence sum: " + computeSum(sequence));
}
private static int calculateProduct(int x, int y) {
int intermediate = x * y;
return intermediate;
}
private static int computeSum(int[] data) {
int total = 0;
for (int val : data) {
total += val;
}
return total;
}
}
Set a breakpoint on int intermediate = x * y; to observe parameter passing and return behavior during the main execution.
Method Breakpoints
Applied directly to method signatures, these breakpoints trigger upon entry or exit. They appear as diamonds in the gutter. When debugging polymorphic calls, the IDE automatically resolves and halts at the concrete implementation, even if the breakpoint is set on a superclass or interface.
package org.devtools.debug;
import java.util.ArrayList;
import java.util.List;
interface DataTransformer {
String transform(String input);
}
class BaseTransformer implements DataTransformer {
@Override
public String transform(String input) {
return "Base: " + input;
}
}
class AdvancedTransformer extends BaseTransformer {
@Override
public String transform(String input) {
return "Advanced: " + input.toUpperCase();
}
}
public class PolymorphicDebugDemo {
public static void main(String[] args) {
// Polymorphic dispatch example
DataTransformer processor = new AdvancedTransformer();
String output = processor.transform("hello world");
System.out.println("Result: " + output);
// List operation example
List<String> records = new ArrayList<>();
records.add("record_1");
records.add("record_2");
// Set method breakpoint on List.add() to observe internal resizing
records.add("record_3");
}
}
Setting a method breakpoint on DataTransformer.transform() allows inspection of which concrete implementation is invoked at runtime. Right-click the breakpoint diamond to toggle Method Entry or Method Exit conditions. The debugger panel will display local variables, call stacks, and thread states, enabling precise fault isolation without modifying source code.