Duplicate line in Visual Studio Code

后端 未结 13 1554
有刺的猬
有刺的猬 2020-12-22 23:25

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

相关标签:
13条回答
  • 2020-12-22 23:39

    Windows:

    Duplicate Line Down : Ctrl + Shift + D

    0 讨论(0)
  • 2020-12-22 23:39

    It's possible to create keybindings that are only active when Vim for VSCode is on and in a certain mode (i.e., "Normal", "Insert", or "Visual").

    To do so, use Ctrl + Shift + P to open up VSCode's Command Palette, then search for "Preferences: Open Keyboard Shortcuts (JSON)"--selecting this option will open up keybindings.json. Here, custom bindings can be added.

    For example, here are the classic VSCode commands to move/duplicate lines tweaked for ease of use in Vim..

        [
          {
            "key": "alt+j",
            "command": "editor.action.moveLinesDownAction",
            "when": "editorTextFocus && vim.active && vim.mode == 'Normal'"
          },
          {
            "key": "alt+shift+j",
            "command": "editor.action.copyLinesDownAction",
            "when": "editorTextFocus && vim.active && vim.mode == 'Normal'"
          },
          {
            "key": "alt+k",
            "command": "editor.action.moveLinesUpAction",
            "when": "editorTextFocus && vim.active && vim.mode == 'Normal'"
          },
          {
            "key": "alt+shift+k",
            "command": "editor.action.copyLinesUpAction",
            "when": "editorTextFocus && vim.active && vim.mode == 'Normal'"
          },
        ]
    

    Now we can use these Vim-friendly commands in VSCode!

    • Alt + J to move a line down
    • Alt + K to move a line up
    • Shift + Alt + J to duplicate a line down
    • Shift + Alt + K to duplicate a line up
    0 讨论(0)
  • 2020-12-22 23:44

    Update that may help Ubuntu users if they still want to use the and instead of another set of keys.

    I just installed a fresh version of VSCode on Ubuntu 18.04 LTS and I had duplicate commands for Add Cursor Above and Add Cursor Below

    Original Keybindings

    I just removed the bindings that used Ctrl and added my own with the following

    Copy Line Up

    Ctrl + Shift +

    Copy Line Down

    Ctrl + Shift +

    New Keybindings

    0 讨论(0)
  • 2020-12-22 23:45

    Another 2 very usefull shortcuts are to move lines selected up and down, like sublime text does...

    {
      "key" : "ctrl+shift+down", "command" : "editor.action.moveLinesDownAction",
      "when" : "editorTextFocus && !editorReadonly"
    },
    

    and

    {
      "key" : "ctrl+shift+up", "command" : "editor.action.moveLinesUpAction",
      "when" : "editorTextFocus && !editorReadonly"
    }
    
    0 讨论(0)
  • 2020-12-22 23:47

    Mac:

    Duplicate Line Down :shift + option +

    Duplicate Line Up:shift + option +

    0 讨论(0)
  • 2020-12-22 23:48

    There is a new command in v1.40: editor.action.duplicateSelection unbound to any keybinding.

    Duplicate selection

    We have added a new action named Duplicate Selection. When executed, the current selection will be duplicated and the result will be selected. When there is no selection, the current line will be duplicated, all without writing to the system clipboard.

    from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_40.md

    Some may find it helpful in certain situations.

    0 讨论(0)
提交回复
热议问题