使用微软的Visual Studio Code,我如何复制一行代码,然后上下移动它?(类似于Sublime的cmd+shift+d行为)

这是一个我经常使用的特性,如果没有它,我很难使用Visual Studio Code。


当前回答

在我的上一个版本Visual Studio Code 1.30.2 它将被自动更改为


ctrl + D

其他回答

你可以找到快捷键

文件>首选项>键盘快捷方式

默认的快捷键是,

向下复制行动作:shift+alt+向下

动作:shift+alt+向上

移动队列动作:alt+向上

向下移动线条动作:alt+向下

或者你可以覆盖键盘快捷键从

文件>首选项>键盘快捷方式

编辑keybindings.json

例子:

[
    {
        "key": "ctrl+d",
        "command": "editor.action.copyLinesDownAction",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+shift+up",
        "command": "editor.action.moveLinesUpAction",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+shift+down",
        "command": "editor.action.moveLinesDownAction",
        "when": "editorTextFocus"
    }
]

ALT + SHIFT +上/下试试

这对我很管用!

适用于Fedora 29工作站(Gnome 3.30.2)和Ubuntu用户。

解绑定不必要的左/右工作区键盘组合,按终端列出

$ gsettings list-recursively | grep -E "org.gnome.desktop.wm.keybindings move-to-workspace-|org.gnome.desktop.wm.keybindings switch-to-workspace-"

解放他们

$ gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left "[]"
$ gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right "[]"
$ gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-left "[]"
$ gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-right "[]"

重置重复的快捷方式

Super+Pgdown/PgUp, Ctrl+Alt+DownArrow/ upparrow Super+Shift+PgDown/PgUp, Ctrl+Alt+Shift+DownArrow/ upparrow

它们可以很容易地重置工作,只有一个快捷方式在设置>设备>键盘 以“移动到上面的工作区”为例,只需再次输入Super+PgUp。

现在在fedora29中有了更少重复的快捷方式,linux上的所有vscode快捷方式都可以正常工作

在VScode中,他们称之为向上复制行和向下复制行

从菜单转到:

文件>首选项>键盘快捷方式

检查已经分配的键盘快捷键,或调整你的。

有时默认分配的快捷方式可能不起作用,主要是由于操作系统。

在我的Ubuntu中,我将其调整为:Ctrl+Shift+D

如果你来自Sublime Text,不想重新学习新的键绑定,你可以使用Visual Code Studio的这个扩展。

Sublime Text Keymap for VS Code 这个扩展端口最流行的Sublime文本键盘快捷键到Visual Studio代码。安装扩展和重新启动VS Code你最喜欢的键盘快捷方式从Sublime文本现在可用。

https://marketplace.visualstudio.com/items?itemName=ms-vscode.sublime-keybindings