VS Code provides powerful and efficient keyboard shortcuts and multi-cursor features for changing lines. You can move, duplicate, and delete lines with simple key combinations or edit multiple lines simultaneously.
Manipulating lines with keyboard shortcuts
Move a line
To move a line of code, place your cursor anywhere on the line and press the following key combination:
- Windows / Linux:
Alt+↑(up arrow) or↓(down arrow) - Mac:
Option+↑or↓
Duplicate a line
To copy and paste a line, place the cursor on the line you want to copy and press:
- Windows / Linux:
Shift+Alt+↑or↓ - Mac:
Shift+Option+↑or↓
Delete a line
To delete a line instantly, place your cursor on the line and use this shortcut:
- Windows / Linux:
Ctrl+Shift+K - Mac:
Command+Shift+K
Insert a new line
To add a new line without moving your cursor to the end of the current line, use one of these commands:
- Insert line below:
Ctrl+Enter - Insert line above:
Ctrl+Shift+Enter
Editing multiple lines simultaneously
Multi-cursor editing
Multi-cursor editing allows you to add or change text on multiple lines at once. You can achieve this in two main ways:
- Windows / Linux: Hold
Ctrl+Altand press the↑or↓arrow key to add cursors to consecutive lines. - Mac: Hold
Option+Commandand press the↑or↓arrow key to add cursors to consecutive lines.
Arbitrary cursors with a mouse
If the lines you want to edit are not consecutive, you can place cursors manually with your mouse:
- Windows / Linux: Hold
Altand click where you want to add an additional cursor. - Mac: Hold
Optionand click where you want to add an additional cursor.
Select and edit all matching text
This is a powerful method for changing multiple lines if you need to replace all instances of a specific word or phrase:
- Double-click a word to select it, or highlight a longer phrase.
- Press
Ctrl+Shift+L(Windows/Linux) orCommand+Shift+L(Mac) to select all other occurrences of that text in the document. - Start typing to replace all instances at once.
Column (box) selection
For bulk edits that align vertically, you can select and edit a rectangular block of code:
- To start: Go to
Selection>Column Selection Modeor pressCtrl+Shift+Alt+↓or↑. - Using the mouse: Hold
Shift+Altand click and drag to draw a box around the text.
Using the Command Palette
For every shortcut mentioned, you can also use the Command Palette, which is helpful if you forget the keybindings.
- Open the Command Palette with
Ctrl+Shift+P(Windows/Linux) orCommand+Shift+P(Mac). - Type a command, such as "Move Line Up," and select it from the list.
Advanced line modifications
Find and Replace
For more complex changes, especially across multiple files, use the Find and Replace feature:
- Open it by pressing
Ctrl+H(Windows/Linux) orCommand+H(Mac). - Enter the text to find in the top field and the replacement text in the bottom field.
- Use the
ReplaceorReplace Allbuttons.
Refactoring and intelligent edits
For more complex code changes, VS Code can automatically suggest edits using built-in features and extensions.
- Smart Rename: Place your cursor on a variable or function and press
F2to rename all references simultaneously. - AI-assisted editing: Extensions like GitHub Copilot can provide intelligent, context-aware suggestions for refactoring and editing code, which can help with complex changes across multiple lines.