Move Code Faster in Visual Studio Code with Alt+Up and Alt+Down
A simple keyboard shortcut that makes rearranging code quick and effortless
Small editing shortcuts can make a big difference over the course of a day. In Visual Studio Code, Alt+Up and Alt+Down let you move the current line, or an entire selected block, without cutting, pasting, or fixing indentation afterward.
How It Works
Place the cursor anywhere on the line you want to move. Then use:
- Alt+Up to move the line up one position.
- Alt+Down to move the line down one position.
You do not need to select the whole line. Visual Studio Code moves it and preserves its contents. If you select several lines first, the editor moves the complete block together.
Example
Imagine these statements are in the wrong order:
const result = calculateTotal();
validateInput();
displayResult(result);
Put the cursor on validateInput(); and press Alt+Up. The validation line moves above the calculation line immediately, with no clipboard operation required.
You can also select multiple lines of code and move them up or down as one block.
Why This Shortcut Is Useful
Moving code directly is faster and safer than cutting and pasting. It is especially handy when you are:
- Reordering statements while debugging.
- Moving a method or property within a class.
- Rearranging configuration entries.
- Refactoring a selected block while preserving its structure.
Related Shortcuts
To duplicate code instead of moving it, use Shift+Alt+Up or Shift+Alt+Down on Windows.
On macOS, use Option+Up and Option+Down to move code.
Customize the Keys
If the shortcut conflicts with another application or operating-system command, open the Keyboard Shortcuts editor with Ctrl+K, Ctrl+S. Search for Move Line Up or Move Line Down, then assign a key combination that works for you.
Final Takeaway
The next time code is in the wrong place, skip cutting and pasting. Put the cursor on the line, press Alt+Up or Alt+Down, and keep your hands on the keyboard.
For more editing shortcuts, see the official Visual Studio Code keyboard shortcuts reference.