如何在Visual Studio Code中创建多个光标

845

在 VS Code 中创建多个光标的键盘快捷键是什么?


184
只需按住“Alt”键,然后在不同的位置开始单击即可。就是这样。 - username
96
CMD+Alt+Down箭头是您想要的操作。 https://dev59.com/Yl0a5IYBdhLWcg3wsKi2 - Valentine Bondar
7
如果您正在使用 Mac,自 1.14.2 起,您实际上需要使用 SHIFT+CTRL+DOWN/UP。 - Ben Creasy
2
此外,根据1.14.2版本的默认设置,似乎Cmd+Alt+Down被映射为editor.action.goToDeclaration。 - Ben Creasy
3
如果你使用的是Mint系统,你可以通过禁用Alt+单击来实现。具体方法是进入“系统设置”-“窗口”-“行为”,然后更改“移动和调整窗口的特殊键”。 - ncesar
显示剩余7条评论
24个回答

17

Ctrl+Alt+⬇ / ⬆可以在当前行上方或下方添加光标。虽然这个功能还不如Sublime或Brackets好用。但是在快捷键文件中,我没有找到类似于Sublime中Ctrl+D的功能。


5
对于 Mac,快捷键是:Alt + Command 和向上或向下箭头。 - Leniel Maccaferri
在Ubuntu上,这是Ctrl+Shift+Up/Down - tobalr
1
在Windows中,似乎默认为“旋转屏幕”。 - BlaM
2
如果屏幕旋转,那是你的显卡驱动程序,而不是Windows。你可以从图形设置中禁用该快捷键。 - Daniel
对我来说可以工作! :) - Phil

9

https://code.visualstudio.com/Updates

新版本(Visual Studio 0.3.0)支持更多的多光标功能。

Multi-cursor
Here's multi-cursor improvements that we've made.

⌘D selects the word at the cursor, or the next occurrence of the current selection.
⌘K ⌘D moves the last added cursor to next occurrence of the current selection.
The two actions pick up the matchCase and matchWholeWord settings of the find widget.
⌘U undoes the last cursor action, so if you added one cursor too many or made a mistake, press ⌘U to return to the previous cursor state.
Insert cursor above (⌥⌘↑) and insert cursor below (⌥⌘↓) now reveals the last added cursor, making it easier to work with multi-cursors spanning more than one screen height (i.e., working with 300 lines while only 80 fit in the screen).

选择多个光标的快捷方式变成了cmd + d(与Sublime Text相同)。

我们期望下一版本将支持更多关于多光标的便捷功能;)


9

1
谢谢,对于Mac也适用。 - Manish

7
在我的XFCE(版本4.12)中,它位于“设置 -> 窗口管理器调整 -> 辅助功能”中。
有一个下拉字段“用于抓取和移动窗口的键:”,将其设置为“无”。
现在,在VS Code中使用Alt + 单击即可添加更多光标。

对于Linux Mint 20,前往菜单->输入窗口->单击“窗口”->选择“行为”选项卡并向下滚动到“移动和调整窗口”部分。将“用于移动和调整窗口的特殊键”更改为与Alt不同的其他内容。 - iamafasha

7
在没有鼠标的情况下使用Visual Studio:Alt+Shift+{箭头}

4
按下 Alt+Shift+{箭头} 将会在 VS Code V1.18.0 中复制当前行。 - Adarsh Madrecha

5
您可以按照选择菜单中的以下步骤进行操作:
按住Alt+Ctrl+Up Arrow/Alt+Ctrl+Down Arrow,创建足够的光标,然后使用Ctrl+D扩展选择。
如下图所示:VS Code 中的选择菜单截图

4
对于xfce用户,只需转到 设置>窗口管理器调整>辅助功能,然后将 用于抓取和移动窗口的键: 更改为 super,如下图所示。enter image description here 现在您可以使用 super 而不是 alt。完成了!!通过 alt + click 来创建多个光标。

3

在Ubuntu-MATE上出现相同问题,但你可以通过以下方法解决:

gsettings set org.mate.Marco.general mouse-button-modifier "<Super>"

2

按下 Alt + Command + Shift 可以在下一个选定实例处添加光标。例如,变量或函数名。


0

首先进入“键盘快捷键”,您可以通过按下Cmd+k然后Cmd+s(对于Windows用户,按下Ctrl+k然后Ctrl+s)来到达那里。

一旦您到达那里,请搜索“在上方添加光标”和“在下方添加光标”。您甚至可以为它们分配自己的快捷键。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接