Move a line or a selection Up or Down in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
2 min

banner

# Move a line Up or Down in Visual Studio Code

To move a line up or down in VS Code:

  • on Windows and Linux, use the Alt key and the up and down arrows.
  • on macOS, use the Option ⌥ key and the up and down arrows.

move line up or down

You can also view the keyboard shortcuts for your operating system in this table in the docs.

The commands are called:

  • Move Line Up
  • Move Line Down
If you hover over the keyboard combination in the Key column, the keyboard shortcuts for all operating systems are displayed.

You can also use the Command Palette to view the keyboard shortcut:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Move Line Up and view the keyboard shortcut.

view keyboard shortcut move line up command

  1. Type Move Line Down and view the keyboard shortcut.

view keyboard shortcut move line down command

# Move a selection up or down in VS Code

The same keyboard shortcuts can be used to move a selection up or down.

  1. Select the text.
  2. Use the Alt (or Option) and the up and down arrow keys to move the selection.

move selection up or down

# Changing the keyboard shortcuts for the Move line up and down commands

If you need to change the keyboard shortcuts for the "move line up" and "move line down" commands:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Type move line up.

change keyboard shortcut move line up

  1. Double-click on the row, set a new keyboard shortcut and hit Enter to confirm.

You can also click on the pencil icon to set a new keyboard shortcut.

  1. Type move line down into the search field.

change keyboard shortcut move line down

  1. Double-click on the row, set a new keyboard shortcut and hit Enter to confirm.

I've also written an article on how to enable relative line numbers in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.