How to Use Multiple Cursors in VS Code

Visual Studio Code (VS Code) allows you to use multiple cursors to edit code in several places simultaneously, drastically reducing the time spent on repetitive editing tasks. This article provides a quick, direct guide to the essential keyboard shortcuts and mouse clicks needed to trigger, manage, and utilize multiple cursors on Windows, macOS, and Linux.

1. The Mouse Click Method (Add Cursor Anywhere)

You can manually position cursors anywhere in your file using a combination of your keyboard and mouse.

2. The Vertical Column Method (Up/Down Cursors)

To insert cursors directly above or below your current cursor position, use the following keyboard shortcuts:

Alternatively, you can hold Shift + Alt (Windows/Linux) or Shift + Option (macOS) and drag your mouse vertically to select a column of text.

3. The “Select Next Occurrence” Method

If you want to edit multiple instances of the same word or variable, you can select them one by one:

  1. Highlight the word you want to change.
  2. Press the shortcut to select the next occurrence and add a cursor to it:
    • Windows / Linux: Ctrl + D
    • macOS: Cmd + D
  3. Repeat the shortcut to keep adding cursors to subsequent occurrences. If you accidentally select too many, press Ctrl + U (Windows) or Cmd + U (macOS) to undo the last selection.

4. The “Select All Occurrences” Method

To instantly add a cursor to every single matching occurrence of a highlighted word in your current file:

5. Add Cursors to the End of Selected Lines

If you have a block of text and want to place a cursor at the very end of each selected line:

  1. Highlight the block of text.
  2. Press the following shortcut:
    • Windows / Linux: Shift + Alt + I
    • macOS: Shift + Option + I

How to Exit Multi-Cursor Mode

Once you are done editing, press the Esc (Escape) key on your keyboard to revert back to a single, standard cursor.