What is Multi-Cursor Editing?
Multi-cursor editing in IntelliJ IDEA allows you to place multiple text cursors (carets) simultaneously in your editor and type or edit text at all those positions at once. Instead of making the same change on multiple lines one by one, you can perform the edit in parallel across all caret locations. This feature dramatically speeds up repetitive editing tasks and is one of the most powerful productivity boosters in the IDE.
IntelliJ IDEA supports two related but distinct concepts:
- Multiple carets (multi-cursor): You manually place additional carets at arbitrary positions using keyboard shortcuts or mouse actions, then type to affect all carets simultaneously.
- Multiple selections: You select multiple ranges of text simultaneously. When you start typing, all selected ranges are replaced, and the carets remain at each position for further editing.
Both modes are deeply integrated into the editor and work seamlessly with code completion, refactoring, and other IDE features.
Why Multi-Cursor Editing Matters
🚀 Deploy your AI agent in 10 minutes
Managed Hermes hosting. Zero DevOps. 100M tokens/mo included.
Try it free →Developers frequently need to make the same structural change across several lines of code. Without multi-cursor support, you would resort to:
- Manual copy-paste and line-by-line editing (slow and error-prone)
- Find-and-replace (works only for simple patterns and risks unintended replacements)
- Writing scripts or macros (overkill for small, ad-hoc edits)
- Duplicate-and-modify workflows (inefficient for more than a few lines)
Multi-cursor editing closes this gap. It gives you the speed of batch editing with the precision of manual, line-by-line control. You see exactly what will change as you type, and you can place carets only where needed, avoiding the collateral damage of broad find-and-replace operations. For refactoring micro-tasks, formatting adjustments, and rapid prototyping, multi-cursor editing is indispensable.
How to Use Multi-Cursor Editing in IntelliJ IDEA
Adding Carets with the Mouse
The simplest way to add carets is using the mouse combined with a modifier key:
- Alt + Shift + Click (Windows/Linux) or Option + Shift + Click (macOS): Places a new caret at the clicked location without removing existing carets.
- Alt + Shift + Click on a different line and then drag: You can also click and drag to place a rectangular selection across multiple lines, which automatically creates carets at the end of each line in the selection.
Each click adds one more caret. You can place carets at completely arbitrary positions — they don't need to be aligned vertically. This is useful when you need to insert or delete text at scattered locations in a file.
Adding Carets with the Keyboard
Keyboard-driven workflows are faster once you learn the shortcuts. The primary keyboard shortcut for adding carets is:
- Alt + Shift + Up/Down (Windows/Linux) or Option + Shift + Up/Down (macOS): Adds a new caret on the line above or below the current caret position. If the lines differ in length, IntelliJ attempts to place the caret at the same visual column.
Repeatedly pressing the arrow key stacks more carets on consecutive lines. This is perfect for editing a contiguous block of lines where each line needs the same modification at the same column offset.
Selecting Multiple Occurrences
Perhaps the most powerful multi-cursor feature is the ability to select the next occurrence of the word under the caret:
- Alt + J (Windows/Linux) or Control + G (macOS): Selects the next occurrence of the current word and adds a caret there. Each subsequent press adds the next occurrence.
- Alt + Shift + J (Windows/Linux) or Control + Shift + G (macOS): Removes the last added occurrence and its caret (undoes the last Alt + J).
This is case-sensitive and word-boundary-aware. It's excellent for renaming a variable or method call across a method body without using the full refactoring rename (which affects the entire project). You can selectively pick which occurrences to edit.
Clone Caret Above/Below
You can duplicate the current line (or lines with selection) while keeping the caret active:
- Ctrl + Alt + Up/Down (Windows/Linux) or Command + Option + Up/Down (macOS): Clones the current caret's line (or selected block) above or below, placing a caret at each cloned line. If you already have multiple carets, all corresponding lines are cloned together.
This is technically a "clone caret" action, not just line duplication — it preserves the multi-cursor state so you can immediately edit the cloned lines.
Select All Occurrences
When you want to edit every occurrence of a word or selection in the current file:
- Ctrl + Alt + Shift + J (Windows/Linux) or Control + Command + G (macOS): Selects all occurrences of the current word or selected text in the file and places carets at each one.
Use this with caution — it selects all matches globally in the file. If you only want matches within a specific scope (like a method), consider using Alt + J repeatedly instead, or first collapse the file regions you don't want to affect.
Working with Multi-Cursor
Once you have multiple carets active, every editing action applies to all of them simultaneously:
- Typing characters: Characters are inserted at every caret position.
- Backspace/Delete: Characters before or after each caret are removed.
- Paste: If you copy a single piece of text, it's pasted at all carets. If you copy multiple lines, the clipboard content is distributed across the carets.
- Code completion: Triggering code completion (Ctrl+Space) shows suggestions; accepting one inserts at all carets.
- Live templates: Expanding a live template applies to all carets.
- Move caret: Left/Right arrow keys move all carets in unison. If carets are on lines of different lengths, they move independently based on their line's actual text.
Exiting Multi-Cursor Mode
To return to a single caret:
- Press Escape: Removes all additional carets and selections, leaving only the primary caret.
- Click anywhere in the editor without holding the modifier key.
- Press Alt + Shift + J repeatedly to remove carets one by one until only one remains.
Practical Examples
Example 1: Renaming Variables in Multiple Lines
Suppose you have a method body where the local variable tempResult needs to be renamed to intermediateValue, but only within this method (not project-wide):
public void processData() {
int tempResult = calculateBase();
tempResult = tempResult + offset;
tempResult = tempResult * multiplier;
return tempResult;
}
Place the caret on the first tempResult (the declaration). Press Alt + J (Windows/Linux) or Control + G (macOS) four times to select all occurrences within the method. Then simply type the new name:
public void processData() {
int intermediateValue = calculateBase();
intermediateValue = intermediateValue + offset;
intermediateValue = intermediateValue * multiplier;
return intermediateValue;
}
All five occurrences are updated simultaneously. Press Escape to return to a single caret.
Example 2: Adding Semicolons to Multiple Lines
You've pasted several lines of code that are missing semicolons:
String name = getUserName()
int age = calculateAge()
double salary = getSalary()
boolean active = isActive()
Place the caret at the end of the first line. Press Alt + Shift + Down (Windows/Linux) or Option + Shift + Down (macOS) three times to add carets at the end of each subsequent line. Then type ;:
String name = getUserName();
int age = calculateAge();
double salary = getSalary();
boolean active = isActive();
All four lines get semicolons in one keystroke. This is much faster than navigating to each line individually.
Example 3: Converting a List of Strings to a SQL IN Clause
You have a list of values that need to be wrapped in single quotes and separated by commas for a SQL IN clause:
apple
banana
cherry
date
elderberry
Place the caret at the start of apple. Press Alt + Shift + Down four times to add carets on all five lines at column 0. Now type ', then press End (all carets jump to their respective line ends), type ',. The result:
'apple',
'banana',
'cherry',
'date',
'elderberry',
Then press Home (all carets go to column 0), press End and backspace the trailing comma on the last line, and finally join all lines. You've transformed a raw list into SQL-ready values in seconds.
Example 4: Wrapping Multiple Lines in HTML Tags
You have a list of items that need <li> tags:
Home
About
Services
Contact
Place carets at the start of all four lines using Alt + Shift + Down. Type <li>. Then press End on all lines and type </li>:
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
This technique works for any repetitive wrapping pattern: quotes, parentheses, brackets, XML/HTML tags, or markdown formatting.
Example 5: Rectangular Selection and Editing
For tabular data or aligned text, you can use rectangular selection combined with multi-cursor. Hold Alt + Shift (Windows/Linux) or Option + Shift (macOS) and drag diagonally across a rectangular region. This creates carets on each line at the selection boundaries. You can then cut, copy, or type across the rectangle. Consider this alignment task:
public static final int STATUS_OK = 200;
public static final int STATUS_NOT_FOUND = 404;
public static final int STATUS_ERROR = 500;
public static final int STATUS_TIMEOUT = 504;
To align the = signs, place a rectangular selection after the constant names, then insert spaces to push the equals signs into alignment. Or use the rectangular selection to extract just the numeric values.
Best Practices
- Start small, expand selectively. Use Alt + J (next occurrence) rather than Select All Occurrences when you only want to change specific instances. It's safer to add occurrences one by one and verify each before typing.
- Keep an eye on the highlighted carets. IntelliJ visually highlights all active caret positions. Before typing, scan the highlights to ensure you haven't accidentally placed a caret somewhere unintended.
- Combine with code folding. If you want to use "Select All Occurrences" but only within a specific method or block, fold the rest of the file first. Occurrences inside folded regions are excluded from the selection.
- Use Escape liberally. If your multi-cursor state gets messy, a single Escape press resets everything. Don't try to manually fix a tangled set of carets — just clear and start fresh.
- Pair with structural navigation. Use Ctrl + W (extend selection) to select the current word before using Alt + J, or use Ctrl + Shift + Left/Right to select word fragments across all carets simultaneously.
- Leverage the clipboard. If you copy text from a single caret, pasting distributes that text to all carets. If you copy multiple lines (one per caret), pasting maps each line to the corresponding caret. This enables powerful column-based copy-paste workflows.
- Don't overuse for large-scale refactoring. Multi-cursor is great for localized, same-file edits. For renaming across an entire project, use IntelliJ's proper refactoring tools (Shift + F6). Multi-cursor shines for ad-hoc, within-method, or within-file changes where formal refactoring would be overkill.
- Practice the keyboard shortcuts until they become muscle memory. The difference between a developer who uses multi-cursor fluently and one who doesn't can be minutes per editing session. Invest the time to learn Alt + J, Alt + Shift + Up/Down, and Escape.
Conclusion
Multi-cursor editing in IntelliJ IDEA transforms repetitive text editing from a tedious, error-prone chore into a fast, precise, and even enjoyable experience. By mastering the handful of keyboard shortcuts — adding carets with Alt + Shift + Up/Down, selecting occurrences with Alt + J, and clearing with Escape — you equip yourself with a tool that bridges the gap between manual editing and automated refactoring. Whether you're renaming variables in a method, formatting lists, wrapping lines in tags, or aligning tabular data, multi-cursor editing lets you make changes with surgical precision at remarkable speed. Integrate these techniques into your daily workflow, and you'll find that many editing tasks that once took minutes now take seconds.