Multiline editing in VS Code (multiple cursors and box selection)
Codemia Knowledge Hub ·
VS Code edits several lines at once with three tools: multiple cursors, box (column) selection, and match-based selection. The most useful single shortcut is Shift+Alt+I (Shift+Option+I on macOS), which puts a cursor at the end of every selected line. These tools work best when the change is local, visible, and repetitive.
Add a cursor to every selected line
The command "add a cursor to the end of each selected line":
- Windows and Linux:
Shift+Alt+I - macOS:
Shift+Option+I
Starting with:
Select the lines, run the command, and type ,:
Use it for suffixes such as commas, semicolons, or trailing comments.
Use box selection for column edits
Some edits are column-shaped rather than line-shaped. Box selection creates a rectangular selection at the same horizontal position across several lines:
Box-select the numeric column and type once to change every line. That is far cleaner than placing ordinary cursors by hand.
Select repeated text by match
When the same text appears several times, build a multi-selection from its matches:
Ctrl+Don Windows and Linux,Cmd+Don macOS: add the next matchCtrl+Shift+Lon Windows and Linux,Cmd+Shift+Lon macOS: select all matches
For example, select one occurrence of temp and press the shortcut until the matches you want are active, then type once to replace them all.
This is good for local text cleanup but not for renaming symbols: it cannot tell code from comments and string literals the way language-aware refactoring can.
Skip a match you do not want
If Ctrl+D or Cmd+D picks up an unwanted match, skip it and move to the next:
- Windows and Linux:
Ctrl+K, thenCtrl+D - macOS:
Cmd+K, thenCmd+D
This helps when a word is mostly in the right context but one occurrence sits in a comment or unrelated string.
Wrapping lines in quotes and punctuation
To turn this list:
into:
- Select the lines.
- Add cursors to the line ends and type
",. - Use box selection at the line starts and type
".
Many small, controlled changes like this avoid copy-paste drift.
Multiline editing vs search-and-replace vs rename
- Multiline editing: visible, local transformations, especially when you want to see every edit point before typing or the change is simple but not uniform enough for a safe replace.
- Search-and-replace: broad, uniform textual patterns.
- Rename refactor: language-aware symbol changes.
Mistakes to avoid
- Using multiline editing for semantic renames that belong to the refactor engine.
- Missing one unwanted match in a multi-selection.
- Forgetting box selection when the problem is really column alignment.
- Reaching for search-and-replace when the target is a small visible block.
- Creating so many cursors that the result becomes hard to predict.
Related reading
- Multiline string literal in C#
- Multiple actions were found that match the request in Web Api
- Multiple awaits vs Task.WaitAll - equivalent?
- Multiple DbContext in .NET Aspire
- Multiple file-extensions searchPattern for System.IO.Directory.GetFiles
- MultipleActiveResultSetsTrue or multiple connections?
- Multiply TimeSpan in .NET
- Must call EndRead in ALL cases?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.