使用微软的Visual Studio Code,我如何复制一行代码,然后上下移动它?(类似于Sublime的cmd+shift+d行为)
这是一个我经常使用的特性,如果没有它,我很难使用Visual Studio Code。
使用微软的Visual Studio Code,我如何复制一行代码,然后上下移动它?(类似于Sublime的cmd+shift+d行为)
这是一个我经常使用的特性,如果没有它,我很难使用Visual Studio Code。
当前回答
对于迁移到VSCode的Jetbrains IDE用户。 安装(人):
JetBrains IDE Keymap:扩展 扩展(首选)
使用这个Intellij Darcula主题:扩展 键图涵盖了VS Code的大部分快捷键,使VS Code更像JetBrains IDE。 以上扩展从JetBrains导入到VS Code的键绑定。安装扩展并重新启动VS Code后,您可以像IntelliJ IDEA, Webstorm, PyCharm等一样使用VS Code。
其他回答
直线复制(没有剪贴板步骤)是由上下文复制扩展提出的。
它被映射到ctrl+K 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"
}
]
适用于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快捷方式都可以正常工作
对于Linux用户:我注意到在Linux上你经常需要使用win键。Windows组合为: CTRL + shift + Alt + up
Linux也一样,只需要添加win键: CTRL + shift + win + Alt + up
我注意到现在有几个组合是这样的。说ctrl + alt + L锁定Linux,但ctrl + win + alt + L为Intellij格式的代码。在Windows下只需按ctrl + alt + L来格式化代码。
它错过了这个问题的答案,“如何复制代码的选择”类似于Sublime的cmd/ctrl+shift+d或Jetbrains的cmd/ctrl+d行为。
从vscode市场安装插件重复选择或行
这个扩展提供了绑定ctrl+d (Windows/Linux)和cmd+d (MacOS)。自定义键盘快捷键首选项->键盘快捷键:
{
"mac": "cmd+d",
"key": "ctrl+d",
"command": "geeebe.duplicateText",
"when": "editorTextFocus"
}
注意:快捷方式也重复行,所以如果你安装它,删除你之前的copyLinesDownAction上的ctrl+d快捷方式(如果你之前做过),否则重复选择可能会出错。