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


当前回答

可以根据“选择”菜单执行以下操作:

根据需要按住Alt+Ctrl+向上箭头/Alt+Ctrl+向下箭头以创建足够的光标,然后可以使用Ctrl+D来展开选择。

其他回答

按Alt键并单击。这可以在Windows和Linux*上运行,也可以在Mac上运行。

Visual Studio Code 0.2现在提供了更多的多光标功能:

多光标改进Ctrl+D(Mac上的Cmd+D)选择光标下的单词或当前选择的单词的下一次出现Ctrl+K Ctrl+D将最后添加的光标移动到光标下或当前选择的单词的下一个出现位置默认情况下,命令使用matchCase。如果查找小部件打开,则查找小部件设置(matchCase/matchWholeWord)将用于确定下一次出现Ctrl+U(在Mac上为Cmd+U)撤消上一个光标操作,因此如果您添加的光标过多或出现错误,可以按Ctrl+U(Mac上为Command+U)返回上一个游标状态。向上或向下添加光标(Ctrl+Alt+up/Ctrl+Alt+down)(Mac上的Cmd+Alt+up/Cmd+Alt+down)现在会显示最后添加的光标,以便于一次在超过1个视口高度上使用多个光标(即选择300行,仅80行适合视口)。这使得引入多个光标变得更加容易

*Linux拖动窗口冲突:

一些发行版(例如Ubuntu)将窗口拖动分配给Alt+LeftMouse,这将与VSCode冲突。因此,最近版本的VSCode允许您在“选择”菜单下的Alt+LeftMouse和Ctrl+LeftMouse之间切换,如另一个答案所述。或者,您可以使用gsettings更改OS密钥绑定,如另一个答案中所述。

在我的XFCE(4.12版)中,它位于“设置”->“窗口管理器调整”->“辅助功能”中。

有一个下拉字段Key用于抓取和移动窗口:,将其设置为None。

Alt+Click现在可以在VS代码中添加更多光标。

从Visual Studio代码0.10.9版开始,您现在可以通过选择多行并按Shift+Alt+I,从选定行创建多个光标

注意:这类似于Sublime Text的Ctrl+Shift+L功能。

资料来源:https://code.visualstudio.com/updates/vJanuary#_thank-你相关PR:https://github.com/Microsoft/vscode/pull/1479

在Ubuntu上,为了启用多光标单击,您需要首先通过运行下面的命令重新分配Alt+click。这是因为默认情况下,Ubuntu使用快捷方式本身并具有优先权。

> gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"

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.lol相同)

我们可以预期,下一个版本支持关于多光标的更方便的功能;)