One of VS Code's most powerful features is multi-cursor editing—the ability to place cursors at multiple locations and type everywhere at once. What takes minutes with find-and-replace can take seconds with multi-cursor, and unlike regex, you can see exactly what you're changing in real time.
Once you master this, you'll never go back to editing one line at a time. Here's everything you need to know about multi-cursor editing in VS Code.
Basic Multi-Cursor Shortcuts
Adding Cursors Manually
| Action | Windows/Linux | Mac |
|---|---|---|
| Add cursor at click position | Alt + Click | Option + Click |
| Add cursor above | Ctrl + Alt + Up | Cmd + Option + Up |
| Add cursor below | Ctrl + Alt + Down | Cmd + Option + Down |
| Undo last cursor | Ctrl + U | Cmd + U |
| Exit multi-cursor mode | Escape | Escape |
Selecting Occurrences (The Power Move)
This is the most commonly used multi-cursor technique:
| Action | Windows/Linux | Mac |
|---|---|---|
| Select next occurrence | Ctrl + D | Cmd + D |
| Skip occurrence | Ctrl + K, Ctrl + D | Cmd + K, Cmd + D |
| Select ALL occurrences | Ctrl + Shift + L | Cmd + Shift + L |
-
Using Ctrl+D Workflow
Select a word or variable name. Press
Ctrl+Drepeatedly to add the next occurrence to your selection. Each press adds another cursor. When you have all the ones you want, just start typing—all cursors type together. -
Select All at Once
If you want to rename a variable everywhere in a file, select it and press
Ctrl+Shift+L. Instant cursors at every occurrence. Type the new name, and you're done.
💡 Pro Tip: Case Sensitivity
Ctrl+D respects case by default. If you want case-insensitive matching, press Ctrl+F to open find, toggle case sensitivity off (Alt+C), then use Ctrl+Shift+L to select all matches.
Column/Box Selection
Perfect for editing aligned data like CSV, JSON, or formatted code:
- Windows/Linux:
Shift + Alt + Drag - Mac:
Shift + Option + Drag
This creates a rectangular selection, placing cursors at the start of each line in the selection. Great for:
- Adding prefixes to multiple lines
- Removing columns of data
- Editing aligned object keys
Practical Examples
Example 1: Rename a Variable
// Before
const userName = "John";
console.log(userName);
return userName.toUpperCase();
// Select 'userName', press Ctrl+Shift+L, type 'displayName'
// After
const displayName = "John";
console.log(displayName);
return displayName.toUpperCase();
Example 2: Add Quotes to Multiple Lines
// Before
apple
banana
cherry
// Put cursor at start of "apple", Ctrl+Alt+Down twice
// Type quote, End key, type quote
// After
"apple"
"banana"
"cherry"
Example 3: Convert Object Keys
// Before
{
first_name: "John",
last_name: "Doe",
phone_number: "555-1234"
}
// Select first '_', Ctrl+D to get all underscores
// Delete underscore, type nothing (or capitalize next letter)
// After (with some adjustment)
{
firstName: "John",
lastName: "Doe",
phoneNumber: "555-1234"
}
Advanced Techniques
Add Cursors to Line Ends
- Select multiple lines
- Press
Shift + Alt + I(Windows) orShift + Option + I(Mac) - Cursors appear at the end of every selected line
Combine with Find & Replace
- Use regex find to locate patterns
- Press
Ctrl+Shift+Lto select all matches - Make complex edits that regex alone can't handle
⚠️ When NOT to Use Multi-Cursor
For simple text replacements across many files, use global find-and-replace instead. Multi-cursor is best for complex edits within a single file where you need visual feedback.
Conclusion
Multi-cursor editing is one of those features that feels like cheating once you master it. Start with Ctrl+D for selecting occurrences—it's the most versatile and commonly used technique. Then gradually add Alt+Click and column selection to your toolkit.
The time you invest in learning these shortcuts will pay back thousands of times over in your coding career.