How do I duplicate the cursor in VS code matching text?

Viewed 20

I want to be able to select a piece of text in VSCode and hit a button and then have it select the next time that same piece of text appears in the document, then hit it again to select the third etc. What I say select, I want to duplicate the cursor. So I can edit multiple occurrences in one go.

I want to know what the actual command is so I can bind a key to it, not the default keybinding for it.

1 Answers

The command is named "Select all occurrences" and it produces one cursor for each occurrence of the word under cursor (or for each occurrence of the current selection, if a selection exists).

It is, by default, triggered by the keyboard combination Ctrl-Shift-L (Cmd-Shift on macOS) but you can assign a different combination if you need.

Another similar key combination is Ctrl-F2 (Cmd-F2). It is named "Change all occurrences".

Besides adding cursors, both commands also select the current word, if a selection does not exist, so that it can be deleted or replaced easily.

Related