Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you create multiple cursors in Visual Studio Code

What are the keyboard shortcuts for creating multiple cursors in VS Code?

like image 578
Kiba Avatar asked Apr 29 '15 20:04

Kiba


People also ask

How do I type multiple cursors?

Hold Ctrl–Shift (Mac) or Ctrl–Alt (Windows) and hit Up or Down Arrow to place an additional text cursor above or below the current cursor. Windows Users: Ctrl–Alt and Arrow keys may rotate the screen. You may need to change or disable those keystrokes in your display settings.

How do I get multiple cursors in Visual Studio Mac?

To use the mouse to insert multiple carets, you must press and hold the Control key and Option key and click where you would like the carets to be entered. You will be in insertion mode as long as the Control and Option keys are held.


1 Answers

Press Alt and click. This works on Windows and Linux*, and it should work on Mac, too.

More multi-cursor features are now available in Visual Studio Code 0.2:

Multi cursor improvements
Ctrl+D (Cmd+D on Mac) selects next occurrence of word under cursor or of the current selection
Ctrl+K Ctrl+D moves last added cursor to next occurrence of word under cursor or of the current selection
The commands use matchCase by default. If the find widget is open, then the find widget settings (matchCase / matchWholeWord) will be used for determining the next occurrence
Ctrl+U (Cmd+U on Mac) undoes the last cursor action, so if you added a cursor too many or made a mistake, you can press Ctrl+U (Cmd+U on Mac) to go back to the previous cursor state. Adding cursor up or down (Ctrl+Alt+Up / Ctrl+Alt+Down) (Cmd+Alt+Up / Cmd+Alt+Down on Mac) now reveals the last added cursor to make it easier to work with multiple cursors on more than 1 viewport height at a time (i.e. select 300 lines and only 80 fit in the viewport).

This makes it a lot easier to introduce multiple cursors

* Linux drag-window conflict:

Some distros (e.g. Ubuntu) assign window dragging to Alt+LeftMouse, which will conflict with VSCode.

So, recent versions of VSCode let you toggle between Alt+LeftMouse and Ctrl+LeftMouse under the Selection menu, as detailed in another answer.

Alternately, you could change your OS key bindings using gsettings as mentioned in another answer.

like image 167
vilicvane Avatar answered Sep 24 '22 02:09

vilicvane