使用Microsoft的Visual Studio代码,如何复制一行代码然后上下移动? (类似于Sublime的cmd + shift + d行为)
这是我不断使用的功能,并且在没有它的情况下使用Visual Studio Code正在努力。
您正在寻找的命令是editor.action.copyLinesDownAction
和editor.action.copyLinesUpAction
。
您可以通过选择“文件”>“首选项”>“键盘快捷键”来查看关联的键绑定
视窗:
Shift + Alt + Down和Shift + Alt + Up
苹果电脑:
Shift + Option + Down和Shift + OptionUp
Linux的:
按Ctrl + Shift + Alt +向下和Ctrl + Shift + Alt +向上
(可能需要使用numpad Down and Up for Linux)
此外,命令editor.action.moveLinesUpAction
和editor.action.moveLinesDownAction
是移动线条的命令,它们在Windows和Mac上与Alt + Down和Alt + Up以及Linux上的Ctrl + Down和Ctrl + Up绑定。
对于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 + PgUp作为示例。
现在,在fedora29中使用较少的重复快捷方式,所有vscode shortcuts for linux都必须正常工作
对于Windows:
要复制 - > shift + alt + up
要复制 - > shift + alt + down
对于mac:
要复制 - > shift + option + up
要复制 - > shift + option + down
对于linux:
要复制 - > ctrl + shift + alt + 8
要复制 - > ctrl + shift + alt + 2
注意:您可以通过按ctrl + shift + p更改visual studio代码的键盘快捷键键盘绑定,然后在托盘中键入打开键盘快捷键然后按Enter键以打开新文件(键盘快捷键文件)您可以看到所有它们上面的快捷方式可以通过在相应的键绑定上单击两次来更改键绑定,然后输入您自己的键绑定,最后按回车键。
希望这会对某人有所帮助!
在我的上一版本Visual Studio Code 1.30.2中它将自动更改为
ctrl + D
你可以找到键盘快捷键
文件>首选项>键盘快捷键
默认键盘快捷键是,
Copy Lines Down Action:shift + alt + down
Copy Lines Up Action:shift + alt + up
Move Lines Up Action:alt + up
向下移动行动: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"
}
]
它错过了这个问题的答案,“如何重复选择代码”类似于Sublime的cmd / ctrl + shift + d或Jetbrains的cmd / ctrl + d行为。
安装插件从VS Code Marketplace重复选择或行
此扩展为ctrl + d(Windows / Linux)和cmd + d(MacOS)提供绑定。自定义键盘快捷键首选项 - >键盘快捷键:
{
"mac": "cmd+d",
"key": "ctrl+d",
"command": "geeebe.duplicateText",
"when": "editorTextFocus"
}
注意:快捷方式也是重复行,所以如果你安装它,删除你之前在copyLinesDownAction
上的ctrl + d快捷方式(如果你之前做过),否则重复的选择可能会出错。
尝试ALT + SHIFT + UP / DOWN
它对我有用!
在VSCode中,Ctrl + CCtrl + V复制下面的整行。
我更喜欢这个接受的答案,因为它只需要一只手就可以做到这一点并且感觉更自然。
接受的答案可能适用于大多数人,但是Down位于键盘的另一侧。所以你有两个选择,双手操作(左手:L Shift + L Alt +右手:上/下),或者用一只手使用右手R Shift + R Alt +向上/向下。在我看来,第二种选择感觉很奇怪。我宁愿使用我的手自然地坐在键盘上的选项,如果它的一只手,甚至更好。
请注意,对于Ubuntu用户(<= 17.4),Unity使用CTRL
+ ALT
+ SHIFT
+ Arrow Key
来跨虚拟工作空间移动程序,这与VS Code快捷方式冲突。您需要重新绑定editor.action.copyLinesDownAction
和editor.action.copyLinesUpAction
以避免冲突(或更改您的工作区键绑定)。
对于使用GNOME的Ubuntu 17.10+,似乎GNOME does not use this keybinding in the same way根据其文档,但如果有人在17.10上使用vanilla工作区可以证实这一点,它可能对将来的求职者有帮助。
如果您来自Sublime Text并且不想重新学习新的键绑定,则可以将此扩展用于Visual Code Studio。
VS代码的Sublime文本键映射
此扩展程序将最流行的Sublime Text键盘快捷方式移植到Visual Studio Code。安装扩展并重新启动VS Code后,您可以使用Sublime Text中最喜欢的键盘快捷键。
https://marketplace.visualstudio.com/items?itemName=ms-vscode.sublime-keybindings
Contextual Duplicate扩展提出了直接行复制(没有剪贴板步骤)。
它映射在ctrl + K D上