Search code examples
visual-studio-codekeyboard-shortcuts

Duplicate line in Visual Studio Code


I am trying to find the shortcut for duplicating a line in Visual Studio Code (I am using 1.3.1) I tried the obvious CTRL + D but that doesn't seem to work.


Solution

  • The default is:

    • Windows / Linux SHIFT+ALT +
    • Mac SHIFT+OPTION +

    To change it, click File > Preferences > Keyboard Shortcuts:

    enter image description here

    Search for copyLinesDownAction or copyLinesUpAction in your keyboard shortcuts


    Update for Ubuntu:

    It seems that Ubuntu is hiding that shortcut from being seen by VSCode (i.e. it uses it probably by its own). There is an issue about that on GitHub.

    In order to work in Ubuntu you will have to define your own shortcut, e.g. to copy the line using ctrl+shift+alt+j and CTRL +SHIFT + ALT + k you could use a keybindings.json like this:

    [
        { "key": "ctrl+shift+alt+j", "command": "editor.action.copyLinesDownAction",
                                        "when": "editorTextFocus && !editorReadonly" },
        { "key": "ctrl+shift+alt+k", "command": "editor.action.copyLinesUpAction",
                                        "when": "editorTextFocus && !editorReadonly" }
    ]