Visual Studio代码中的多行编辑

本文翻译自:Multiline editing in Visual Studio Code

Is it possible to enable multiline editing like in Sublime Text ? 是否可以像Sublime Text一样启用多行编辑?

For example, press Ctrl to place additional cursor carets and being able to write/delete on multiple places in the document at one time. 例如,按Ctrl键可以放置其他光标插入符,并且可以一次在文档中的多个位置写入/删除。


#1楼

参考:https://stackoom.com/question/222Cm/Visual-Studio代码中的多行编辑


#2楼

On Windows, you hold Ctrl + Alt while pressing the up or down arrow keys to add cursors. 在Windows上,按住Ctrl + Alt,同时按向上或向下箭头键添加光标。 On Mac and Linux, the equivalents are ⌥ Opt + ⌘ Cmd + / and Shift + Alt + / , respectively. 在Mac和Linux上,等效项分别为⌥Opt + ⌘Cmd + / Shift + Alt + /

Note that third-party software may interfere with these shortcuts, preventing them from working as intended (particularly Intel's HD Graphics software on Windows; see comments for more details). 请注意,第三方软件可能会干扰这些快捷方式,从而阻止它们按预期工作(尤其是Windows上的英特尔高清显卡软件;有关详细信息,请参阅注释)。

If you experience this issue, you can either disable the Intel/other software hotkeys, or modify the VS Code shortcuts (described below). 如果遇到此问题,可以禁用Intel /其他软件热键,或修改VS Code快捷方式(如下所述)。

Press Esc to reset to a single cursor. Esc键重置为单个光标。

Visual Studio Code中的多行游标

Or, as Isidor Nikolic points out , you can hold Alt and left click to place cursors arbitrarily. 或者, 正如Isidor Nikolic指出的那样 ,您可以按住Alt并左键单击以任意放置光标。

在Visual Studio Code中任意放置多行游标

You can view and edit keyboard shortcuts via: 您可以通过以下方式查看和编辑键盘快捷键:

File → Preferences → Keyboard Shortcuts 文件→首选项→键盘快捷键

Documentation: 文档:

https://code.visualstudio.com/docs/customization/keybindings https://code.visualstudio.com/docs/customization/keybindings

Official VS Code Keyboard shortcut cheat sheets: 官方VS Code键盘快捷键备忘单:

https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf


#3楼

You can just Alt + click for additional cursors. 您只需按住Alt键并单击其他游标即可。 And as already mentioned, Ctrl + Alt + or . 如前所述, Ctrl + Alt +


#4楼

On Mac it is: 在Mac上它是:

Option + Command while pressing the up or down arrow keys. 按下向上或向下箭头键时按Option + Command


#5楼

(Windows 10 pro x64) Here have some ways! (Windows 10专业版x64)这里有一些方法!

  1. Alt + click 按住Alt并 单击

  2. Alt + Ctrl + up / down Alt + Ctrl + 向上 / 向下

  3. Keybindings: Ctrl + click (??? it doesn't work!) 键绑定: Ctrl + click (???它不起作用!)

在此输入图像描述


#6楼

I think it depends on your Visual Studio Code version. 我认为这取决于您的Visual Studio代码版本。

Mine is Linux version Visual Studio Code 1.7.2. 我的是Linux版Visual Studio Code 1.7.2。

                                     "when": "editorTextFocus" },
{ "key": "shift+alt+up",          "command": "editor.action.insertCursorAbove",
                                     "when": "editorTextFocus" },
{ "key": "ctrl+shift+down",       "command": "editor.action.insertCursorBelow",
                                     "when": "editorTextFocus" },
{ "key": "shift+alt+down",        "command": "editor.action.insertCursorBelow",
                                     "when": "editorTextFocus" }```

The point is the shortcuts are not same in all machines, so you should check your configuration. Go to menu:

> Menu *File* → *Preferences* → *Keyboard Shortcuts*

Search for `editor.action.insertCursorAbove` and `editor.action.insertCursorBelow` and see your current configurations. You may change them if they conflict with operating system's shortcut keys.



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章