本文翻譯自: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鍵重置爲單個光標。
Or, as Isidor Nikolic points out , you can hold Alt and left click to place cursors arbitrarily. 或者, 正如Isidor Nikolic指出的那樣 ,您可以按住Alt並左鍵單擊以任意放置光標。
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)這裏有一些方法!
Alt + click 按住Alt並 單擊
Alt + Ctrl + up / down Alt + Ctrl + 向上 / 向下
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.