Visual Studio代码中的多个游标[关闭]

问题描述 投票:445回答:19

在VS Code中编辑时如何创建多个游标?我对macOS和Windows都很感兴趣。

visual-studio-code
19个回答
464
投票

按Alt并单击。这适用于Windows和Linux *,它也适用于Mac。

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

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

这使得引入多个游标变得更加容易

* Linux拖窗冲突:

一些发行版(例如Ubuntu)将窗口拖动到Alt + LeftMouse,这将与VSCode冲突。

因此,最新版本的VSCode允许您在Selection菜单下的Alt + LeftMouse和Ctrl + LeftMouse之间切换,详见another answer

或者,您可以使用gsettings中提到的another answer更改操作系统键绑定。


16
投票

对于你想要的东西没有任何约束力。

唯一接近的是Ctrl + F2,它将立即选择所有这些。

您可以将其绑定到Ctrl + D,执行以下操作:

  • 点击File > Preferences > Keyboard Shortcuts 您应该看到一个窗格,其中包含当前绑定,右侧是自定义绑定列表
  • 在当前绑定中,搜索Ctrl + F2并复制整行并将其粘贴到右窗​​格中。
  • 您可能必须删除末尾的逗号,然后将Ctrl + F2更改为Ctrl + D,然后保存文件。

它应该看起来像这样:

// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+d",               "command": "editor.action.changeAll",
                                    "when": "editorTextFocus" }
]

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相同。大声笑)

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


8
投票

Alt +点击。它适用于Windows。

详细信息:Visual Studio Code Documentation


8
投票

Ctrl + Alt +⬇/⬆在当前行的上方和下方添加光标。尽管如此,仍然远不如崇高或括号那么好。在键盘快捷方式文件中,我无法在sublime中看到与Ctrl + D等效的内容。


7
投票

在没有鼠标的Visual Studio中:Alt + Shift + {Arrow}。


4
投票

在我的XFCE(版本4.12)中,它位于Settings -> Window Manager Tweaks -> Accessibility中。

有一个下拉字段Key used to grab and move windows:,设置为None

Alt + Click现在可以在VS Code中使用以添加更多光标。


4
投票

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

Screenshot of Selection menu in VS Code

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


3
投票

Ubuntu-MATE上的问题相同,但是你可以通过以下方式解决它:

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

2
投票

Alt + Command + Shift会将光标添加到您选择的下一个实例中。例如。变量或函数名称


-3
投票

Alt + Click在OSX中有效。代码版本1.14.2


131
投票

我有ALT键的问题,修复是将alt+click更改为一个Gnome热键,在VSCode中删除多光标选择,运行到super+click

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

资料来源:http://2buntu.com/articles/1529/visual-studio-code-comes-to-linux/


121
投票

Multi-word (and multi-line) cursors/selection in VS Code

多字:

Ondos / AS:

  • Ctrl + Shift + L / Cmd + Shift + L选择当前突出显示的单词的所有实例
  • Ctrl + D / Cmd + D选择下一个实例...以及之后的那个......等等。

多行:

对于多行选择,Ctrl + Alt + Down / Cmd + Alt + Down会将您的选择或光标位置扩展到下一行。 Ctrl + Right / Cmd + Right将移动到每行的末尾,无论多长时间。要逃避多行选择,请点击Esc。

查看VS Code keybindings(操作系统敏感)


103
投票

2017年5月 从版本1.13开始,使用Ctrl / Cmd + Click添加多个游标

VSCode开发人员引入了一个新设置editor.multiCursorModifier,用于更改在macOS上将多个游标应用于Cmd + Click的修改键以及Windows和Linux上的Ctrl + Click。这使得来自其他编辑器(如Sublime Text或Atom)的用户可以继续使用他们熟悉的键盘修饰符。

设置可以设置为:

  • ctrl/Cmd - 在Windows上映射到Ctrl,在macOS上映射到Cmd。
  • alt - 现有的默认Alt。

Click菜单中还有一个新的菜单项使用Ctrl + Multi-CursorSelection快速切换此设置。 enter image description here

Go To Definition和Open Link手势也将尊重此设置并进行调整,使其不会发生冲突。例如,当设置为ctrl/Cmd时,可以使用Ctrl / Cmd + Click添加多个游标,并且可以使用Alt + Click调用打开链接或转到定义。

通过修复问题#2106,现在可以通过在现有选择之上使用相同的手势来移除光标。


72
投票

尝试按Ctrl + Alt + Shift +⬇/⬆,不使用鼠标,或按住“alt”并单击所需的所有行。

注意:在Windows上测试。


40
投票

Cmd + Option +Shift⬇/⬆适用于我最新的VSCode 1.29.1和最新的OSX High Sierra 10.13.6,Macbook Pro。

这会在屏幕上添加垂直线向上/向下,就像Sublime Text中的Option + Click / Vertical Drag一样。

要在文件中的任何点添加多个游标,包括同一行中的多个游标,请执行Cmd(或Option)+单击所需的任何位置,如this video所示。您也可以搜索多次重复的文本(Cmd + F),然后按Option + Return在每个单词结尾处添加光标。


30
投票

在Ubuntu上,为了启用多光标点击,您需要先通过运行以下命令重新分配Alt + click。这是因为默认情况下Ubuntu使用快捷方式本身,并且优先级高。

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

22
投票

在XFCE上,转到Applications -> Settings -> Settings editor - > xfwm4 -> easy_click(disable value)

现在你可以使用Alt + Click来Insert Cursor

我还在Settings -> Window manager -> Keyboard中禁用了L / R工作区(ctrl + alt + L / R)设置


19
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.