How to Move Code Lines Up or Down in VS Code
Rearranging your code quickly is essential for maintaining an efficient programming workflow. This article explains the absolute easiest way to move a single line or an entire block of code up or down in Visual Studio Code (VS Code) using simple, built-in keyboard shortcuts, eliminating the need for tedious copying and pasting.
The Keyboard Shortcuts
The fastest way to move lines of code in VS Code is by using the following keyboard shortcuts:
- Windows & Linux:
Alt+Up ArroworDown Arrow - macOS:
Option+Up ArroworDown Arrow
How to Move a Single Line
- Place your cursor anywhere on the line of code you want to move (you do not need to highlight the text).
- Press and hold the Alt key (Windows/Linux) or the Option key (macOS).
- Press the Up Arrow key to move the line up, or the Down Arrow key to move it down.
How to Move Multiple Lines (Block of Code)
- Highlight the block of code you want to move.
- Press and hold the Alt key (Windows/Linux) or the Option key (macOS).
- Press the Up Arrow or Down Arrow key to slide the entire selected block of code to its new position.