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.



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