我试图找到在Visual Studio代码中复制一行的快捷方式(我使用1.3.1),我尝试了明显的CTRL + D,但似乎不起作用。


当前回答

另外2个非常有用的快捷键是上下移动选定的行,就像sublime text…

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

and

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

其他回答

根据操作系统的不同,可以使用以下方法:

窗口:

Shift+ Alt + ↓ 或 Shift+ Alt + ↑

Mac:

Shift +Option +↓或Shift +Option +↑

Linux:

Ctrl+Shift+Alt+↓或Ctrl+Shift+Alt+↑

注意:对于一些linux发行版使用Numpad箭头

如果Ubuntu用户仍然想使用↑和↓键而不是另一组键,这个更新可能会帮助他们。

我刚刚在Ubuntu 18.04 LTS上安装了一个新版本的VSCode,上面添加光标和下面添加光标的命令都是重复的

原来的快捷键

我只是删除了使用Ctrl的绑定,并添加了自己的绑定

拷贝顺序

Ctrl + Shift +↑

拷贝行向下

Ctrl + Shift +↓

新快捷键

复制可以通过CTRL+C和CTRL+V实现,光标在行中,没有任何选择。

可以创建仅在Vim for VSCode打开并处于特定模式(即“正常”、“插入”或“可视”)时才激活的键绑定。

为此,使用Ctrl + Shift + P打开VSCode的命令面板,然后搜索“首选项:打开键盘快捷键(JSON)”选择这个选项会打开keybindings.json。在这里,可以添加自定义绑定。

例如,这里是经典的VSCode命令移动/复制行调整,以方便在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'"
      },
    ]

现在我们可以在VSCode中使用这些vim友好的命令了!

Alt + J向下移动一行 Alt + K向上移动一行 Shift + Alt + J复制一行 Shift + Alt + K复制一行

另外2个非常有用的快捷键是上下移动选定的行,就像sublime text…

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

and

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