Visual Studio Code
Programming
Coding Tips
Software Development
Code Editor

How can you create multiple cursors in Visual Studio Code

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Multiple cursors are one of the highest-leverage editing features in Visual Studio Code. Instead of repeating the same change line by line, you create several active carets and type once, which is especially useful for local, visible edits that do not justify a full refactor or global replace.

Manual Cursor Placement

The most direct technique is mouse-based:

  • Windows and Linux: Alt + click
  • macOS: Option + click

Each click adds another cursor where you place it. This works well when the target locations are visually obvious but not identical text matches.

For example, if you need to add commas to a few unrelated lines, manual placement is often faster than any selection command.

Add Cursors Above Or Below

If the edit points line up vertically, use stacked cursors instead of repeated clicking:

  • Windows and Linux: Ctrl+Alt+Down and Ctrl+Alt+Up
  • macOS: Option+Cmd+Down and Option+Cmd+Up

This creates one cursor per line directly above or below the current cursor.

That is useful for editing a block like this:

typescript
const user1 = "Ana"
const user2 = "Ben"
const user3 = "Cara"

Put the first cursor on the number or the name, add cursors downward, and edit the whole column at once.

Select Matching Occurrences

When the same text appears repeatedly, VS Code can create multiple cursors from the current selection:

  • 'Ctrl+D on Windows and Linux'
  • 'Cmd+D on macOS'

Each keypress adds the next occurrence of the selected text. This is ideal when you want a few matches, not every match in the file.

If you want all current matches immediately:

  • 'Ctrl+Shift+L on Windows and Linux'
  • 'Cmd+Shift+L on macOS'

That is convenient for simple text edits. For actual symbol renames in code, the language-aware rename action is usually safer because it respects scope and syntax.

Add One Cursor To Every Selected Line

The official VS Code productivity docs highlight a very useful shortcut: place a cursor at the end of every selected line.

  • Windows and Linux: Shift+Alt+I
  • macOS: Shift+Option+I

This is perfect for adding a suffix such as a comma or semicolon:

text
alpha
beta
gamma

After selecting those lines and using the shortcut, typing , gives:

text
alpha,
beta,
gamma,

Box Selection And Column Edits

When text is column-shaped, box selection is often better than ordinary cursor stacking. It lets you create a rectangular selection and type at the same horizontal position on multiple lines.

This is useful for:

  • inserting a prefix at the same column on many lines
  • editing a fixed-width block of text
  • aligning repeated values in structured data

It is one of the best ways to edit tabular data in a general-purpose editor without reaching for a spreadsheet.

The editor.multiCursorModifier Setting

VS Code also lets you choose which modifier key is used for mouse-based multiple cursors through the editor.multiCursorModifier setting. That matters if the default conflicts with other gestures on your platform or window manager. If cursor placement feels wrong, check the setting before assuming the feature is broken.

When Multiple Cursors Are The Wrong Tool

Multiple cursors are still plain text editing. Use them when you can see the exact edit points and want to control them manually. Use something else when the change is semantic or global:

  • multi-cursor for local repeated edits
  • rename refactor for identifiers and symbols
  • search-and-replace for broad file-wide patterns

Choosing the right tool matters more than memorizing every shortcut.

Common Pitfalls

  • Using multiple cursors for symbol renames that should be handled by the rename refactor.
  • Creating too many cursors at once and not noticing one is in the wrong place.
  • Forgetting that Ctrl+D and Cmd+D select text matches, not semantic references.
  • Ignoring Shift+Alt+I or Shift+Option+I when the task is just adding the same suffix to many lines.
  • Overlooking the editor.multiCursorModifier setting when mouse gestures do not behave as expected.

Summary

  • Use Alt or Option click for manual cursor placement.
  • Use stacked cursors for vertically aligned edits.
  • Use Ctrl+D or Cmd+D for the next match and Ctrl+Shift+L or Cmd+Shift+L for all matches.
  • Use Shift+Alt+I or Shift+Option+I to put a cursor at the end of every selected line.
  • Prefer multiple cursors for local text edits, not semantic refactors.

Course illustration
Course illustration

All Rights Reserved.