Hashim Aziz
Hashim Aziz

Reputation: 6175

Is it possible to quickly swap lines in VS Code?

I'm currently experimenting with VS Code, having used Sublime Text 3 for the last five years or so. In Sublime, I could quickly swap two lines by selecting them both and then doing Ctrl+T.

As far as I've been able to find, the only equivalent command in VS Code is Alt+/, which pushes the selected line either up or down, and would be excruciatingly slow unless the selections are very close to each other.

Is this still true as of 2019? Is this basic functionality really not possible in VS Code?

Upvotes: 0

Views: 4784

Answers (1)

Gino Mempin
Gino Mempin

Reputation: 29699

There is no built-in functionality.

You can use a combination of VS Code's multi-cursor selection and the Swap extension.

enter image description here

  1. Select one line or lines
  2. Select another line/lines while holding down Alt or CMD (for Mac)
  3. Use the extension's swap shortcut
    • Via keyboard shortcut

      Windows: CTRL+ALT+8
      Mac: CMD+OPTION+8

    • Via command palette
      • "Swap"

You can customize the keyboard shortcut to be same as what you used in Sublime.

enter image description here

Upvotes: 3

Related Questions