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.
- Windows / Linux: Hold
Altand click where you want to add a new cursor. - macOS: Hold
Optionand click where you want to add a new cursor.
2. The Vertical Column Method (Up/Down Cursors)
To insert cursors directly above or below your current cursor position, use the following keyboard shortcuts:
- Windows:
Ctrl + Alt + Up ArroworCtrl + Alt + Down Arrow - macOS:
Cmd + Option + Up ArroworCmd + Option + Down Arrow - Linux:
Shift + Alt + Up ArroworShift + Alt + Down Arrow
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:
- Highlight the word you want to change.
- Press the shortcut to select the next occurrence and add a cursor to
it:
- Windows / Linux:
Ctrl + D - macOS:
Cmd + D
- Windows / Linux:
- Repeat the shortcut to keep adding cursors to subsequent
occurrences. If you accidentally select too many, press
Ctrl + U(Windows) orCmd + 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:
- Windows / Linux:
Ctrl + Shift + L - macOS:
Cmd + Shift + L
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:
- Highlight the block of text.
- Press the following shortcut:
- Windows / Linux:
Shift + Alt + I - macOS:
Shift + Option + I
- Windows / Linux:
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.