Multiple Cursors: Edit Many Lines at Once in a Code Editor
Multiple cursors editing means placing several text cursors at once, so whatever you type, delete, or paste happens in every place together. You can add cursors with a click, stack them down adjacent lines, or select every match of a word. The shortcuts below are the ones VS Code documents; other editors often offer the same idea under different keys.
Quick answer
Hold Alt (Option on a Mac) and click to drop an extra cursor anywhere. Press Ctrl+D (Cmd+D on a Mac) to select the next match of the current word, or Ctrl+Shift+L (Cmd+Shift+L) to select every match. Press Esc to go back to one cursor. That covers most everyday jobs: one prefix on ten lines, one rename in a file, one missing quote down a column of values.
How it actually works
Every extra cursor behaves like the main one. Type a character and it appears at each cursor; press Backspace and each cursor deletes one character; paste and the text lands at all of them. There are three common ways to place them.
Add a cursor with the mouse
According to the VS Code basic editing docs, you add secondary cursors, drawn thinner than the main one, with Alt+Click. Click as many places as you like. They don't need to line up. It's FOSS notes that Esc cancels all the extra cursors and returns you to one.
Stack cursors on adjacent lines
To edit a block of consecutive lines, add cursors above or below the current one with the keyboard. VS Code lists Option+Cmd+Up/Down on macOS, Ctrl+Alt+Up/Down on Windows, and Shift+Alt+Up/Down on Linux. The docs also warn that a graphics card driver (NVIDIA is the example) might overwrite these defaults, so if nothing happens, check your system shortcuts first.
For a rectangle of text, column (box) selection works too: place the cursor in one corner, then hold Shift+Alt while dragging to the opposite corner.
Select the next or every occurrence
Ctrl+D (Cmd+D on a Mac) selects the word at the cursor, then the next occurrence of the current selection each time you press it. If it grabs one you don't want, Ctrl+K Ctrl+D (Cmd+K Cmd+D) skips it. Ctrl+Shift+L (Cmd+Shift+L) adds a selection at every occurrence of the selected text at once.
Here is a small example. You have a list of values and want each one quoted and followed by a comma:
red
green
blueClick at the start of red, add cursors on the next two lines with the keyboard, and type ". Press End, type ",, and you get:
"red",
"green",
"blue",One pass, no find and replace, and you watch the result form as you type. If you remember comment markers, the same trick comments out a block: stack cursors down the lines and type // or # once.
When to use it (and when to skip it)
Multiple cursors fit best when the same small edit repeats but the surrounding text differs a little. Typical cases from the tutorials we read:
- Renaming a variable or function in several places in one file.
- Adding or removing the same snippet across several lines.
- Editing repeated structures such as object keys, class names, or attribute values, like the repeated structures in YAML files.
- Editing columns in CSV data or log output.
Skip it, or reach for another tool, when:
- Renaming across files. VS Code's Rename Symbol (F2) renames all usages of a symbol, across files, in languages that support it. Multiple cursors only see the current file and don't know what a symbol is.
- One change across a whole file. Plain find and replace is simpler, and it supports regular expressions.
- Repeated templates with fill-in spots. Snippet tabstops let you jump between the blanks.
A few pitfalls. Select-all is powerful, but It's FOSS cautions to use it with care in large files so you don't make unintended edits. If you press Ctrl+D one time too many, Cmd+U undoes the last cursor operation (this one comes from a 2019 Atomic Object walkthrough written for macOS, so check your own keymap). And if cursors sit at uneven positions across lines, your edits won't match up.
Two VS Code settings matter here. editor.multiCursorModifier can switch the click modifier to Ctrl/Cmd+Click, which helps if Alt+Click is taken by your window manager. editor.multiCursorPaste controls pasting: the default spread hands one pasted line to each cursor, while full pastes the whole text at every cursor.
How Carets fits in
Multiple cursors are a text-editor feature, and the keys above belong to VS Code, so check what your own editor supports before you rely on them. Carets doesn't claim to copy that workflow. It covers the other half of the job: keeping your text organized and readable on iPhone, iPad, and Mac.
Carets is a native notes and code editor, not a web wrapper. It edits Markdown, plain text, and code in one place, with syntax highlighting for code and config files, and it organizes everything into files, projects, and tags. Your files stay plain text, so you can open the same snippet or list in any other editor, multi-cursor shortcuts included, when a big batch edit calls for it.
If you write code snippets, edit config files, or keep notes in Markdown on your phone, tablet, and Mac, download Carets on the App Store for iPhone, iPad, and Mac.
Frequently Asked Questions
How do I get back to one cursor?
Press Esc in VS Code, which cancels all the extra cursors. If you only want to undo the last cursor you added, Cmd+U (on macOS) undoes the last multi-cursor operation.
What is the difference between Ctrl+D and Ctrl+Shift+L?
Ctrl+D (Cmd+D on a Mac) selects the word, then the next occurrence each time you press it, so you control how many matches you take. Ctrl+Shift+L (Cmd+Shift+L) selects every occurrence in the file at once.
Why does Alt+Click do nothing on my machine?
Some systems use Alt+Click for something else, such as moving windows, and graphics drivers can override the cursor shortcuts. VS Code lets you switch to Ctrl/Cmd+Click with the editor.multiCursorModifier setting.
Should I use multiple cursors or find and replace?
Use find and replace for one change across a whole file. Use multiple cursors when each line needs the same edit in a slightly different spot and you want to see the result as you type.