VSCode - multiple cursors

Published: | by Julian Knight Reading time ~2 min.
📖 Kb | 📎 Development | 🔖 vscode

VSCode supports multi-cursor editing, here are some tips on using it.

Note that, in multi-cursor mode, the standard selection shortcuts also work.

Change all the same text in a document to something else 🔗︎

If you want to quickly change all of the same text in a document:

  • Select the text or code that you want to change. VSCode highlights all matching text.
  • Press Ctrl+F2 and type your new text.

VSCode supports multi-cursor editing which this tip makes use of.

Multi-cursor mouse shortcuts 🔗︎

  • Alt and click will add additional cursors. (Note that some Linux distributions may map a system function to Alt+LeftMouse which may interfere with this shortcut).
  • Shift+Alt and drag does a box select with cursors on every line selected.

Multi-cursor keyboard shortcuts 🔗︎

  • Ctrl+Alt+Up, Ctrl+Alt+Down extends multiple cursors upwards and downwards from the previously selected cursors. Note that using both up and down after each other extends around the previous cursors.
  • Ctrl+D 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 undoes the last cursor action, so if you added a cursor too many or made a mistake, you can press Ctrl+U to go back to the previous cursor state. Adding cursor up or down (Ctrl+Alt+Up, Ctrl+Alt+Down) 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).

  • Ctrl+Shift+Alt+Up, Ctrl+Shift+Alt+Down, Ctrl+Shift+Alt+Left, Ctrl+Shift+Alt+Right, Ctrl+Shift+Alt+PageUp, Ctrl+Shift+Alt+PageDown extend selections of box-selections. If standard multi-cursors selected, will box-select around the first cursor.

These shortcuts are not available on Linux

Some options don’t appear to work on my Windows 10 installation - possibly due to clashing shortcuts from extensions:

  • Alt+Shift+L Selects all the same words that the first cursor is in. (Similar to selecting text and then Ctrl+F2). This works from the menu but not from the keyboard shortcut.
  • Alt+Shift+I extend cursor selections to end of line.

Changing the keyboard modifier 🔗︎

The editor.multiCursorModifier can be set to either:

  • ctrlCmd - Maps to Ctrl on Windows and Cmd on macOS.
  • alt - The default Alt.

This can also be toggled from the Selection menu.

Multi-cursor menu items 🔗︎

The Selection menu has a number of entries related to multiple cursors.



Share this:
comments powered by Disqus