Visual Studio Code
Multiline Editing
Coding
Programming Tools
Software Development

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:

text
alpha
beta
gamma

Select the lines, run the command, and type ,:

text
alpha,
beta,
gamma,

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:

text
id:   1
id:   2
id:   3

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+D on Windows and Linux, Cmd+D on macOS: add the next match
  • Ctrl+Shift+L on Windows and Linux, Cmd+Shift+L on 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, then Ctrl+D
  • macOS: Cmd+K, then Cmd+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:

text
apple
banana
carrot

into:

text
"apple",
"banana",
"carrot",
  1. Select the lines.
  2. Add cursors to the line ends and type ",.
  3. 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.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data 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.

Practice algorithms