editorvisual-studio-codekeyboard-shortcuts

How do I duplicate a line or selection within Visual Studio Code?


Using Microsoft's Visual Studio Code, how do I duplicate a line of code and then move it up and down? (Similar to Sublime's cmd+shift+d behaviour)

It's a feature that I use constantly, and am struggling using Visual Studio Code without it.


Solution

  • The commands your are looking for are editor.action.copyLinesDownAction and editor.action.copyLinesUpAction.

    You can see the associated keybindings by picking: File > Preferences > Keyboard Shortcuts

    Windows:

    Shift+Alt+Down and Shift+Alt+Up

    Mac:

    Shift+Option+Down and Shift+OptionUp

    Linux:

    Ctrl+Shift+Alt+Down and Ctrl+Shift+Alt+Up

    (Might need to use numpad Down and Up for Linux)

    Furthermore, commands editor.action.moveLinesUpAction and editor.action.moveLinesDownAction are the ones to move lines and they are bound to Alt+Down and Alt+Up on Windows and Mac and Ctrl+Down and Ctrl+Up on Linux.