Productive— faster every day
For your professionTeachersStudentsManagersMarketingDevelopersFreelancersParents

Tips & tricks · Shortcuts · Everywhere · ~5 min a day · 2 min read

Alt+arrows: move lines of code instead of cutting and pasting

Last reviewed:

Alt+Shift+Alt+

Illustration for: Alt+arrows: move lines of code instead of cutting and pasting

Moving a line of code three positions down is one of the most common small edits there is — and the classic approach of select, cut, navigate, paste has a surprising number of steps and one trap: the clipboard, whose contents you end up overwriting. Editors handle it in one motion: Alt + / moves the current line up or down while you watch it travel through the code in real time. The sibling shortcut Shift + Alt + / duplicates the line — the foundation for every “same thing, just a different value” kind of edit.

How to do it

  1. Put the cursor anywhere on the line you want to move — you don't need to select anything. Press Alt + or Alt + and the line swaps places with its neighbor; hold and press repeatedly until it lands where it belongs.
  2. Multiple lines at once: select them (even partially) and the same shortcut moves the whole block together.
  3. Duplicating: Shift + Alt + creates a copy of the line or selected block right below the original — and the clipboard stays untouched, so you don't lose whatever was in it.
  4. On a Mac it's Option + arrows, or Shift + Option + arrows for duplicating. The shortcuts work in VS Code; in JetBrains IDEs, Shift + Alt + arrows moves a line and Ctrl + D duplicates it.
  5. In VS Code, moving also triggers automatic indentation adjustment — when you move a line inside a block, the editor adapts its indentation.

A typical scenario

A developer is assembling a configuration: a list of rules where order matters. One rule needs to move above the others — Alt+up arrow, four times, done, and the whole time she can see exactly where the line is. Then she adds three nearly identical entries: Shift+Alt+down arrow three times duplicates the pattern, and she only rewrites the values in the copies. A year ago the same task would have been a minute of selecting, cutting, and pasting — with the risk of overwriting the clipboard that held a chunk of text copied from documentation.

Duplicating is worth promoting into a habit when writing new code too: instead of writing a similar line from scratch, duplicate the neighboring one and edit the difference. It's faster and more consistent — the structure, spacing, and punctuation stay the same, and you only touch what actually differs.

What you get out of it

The micro-edits you make ten times a day shrink to one motion and stop destroying the contents of your clipboard. Moving “while watching” also means fewer mistakes — you drop the line exactly where it belongs instead of counting lines before pasting. Together with multi-cursor editing, it forms the core toolkit of fast editing that strips the mechanical drudgery out of writing code.