Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multi-cursor with regex search in Visual Studio Code? [duplicate]

I'm trying to use multi-cursor to select multiple occurrences of a regular expression search in Visual Studio Code, but I can't figure out how to make multi-cursor use the regex pattern instead of just the selected text.

Here's what I'm doing:

  1. Search for my regular expression using the "Find" featureCmd + F).
  2. Put my cursor in the text editor at the location where I want to start my multi-cursor selection.
  3. Press Cmd + D to select the next occurrence of the selected text.
  4. Repeat step 3 until I've selected all the occurrences I want.

Problem is, when you the text editor (step 2), it's not using the regex pattern anymore.

How can I use multi-cursor with regex search in Visual Studio Code?

  • Is there a setting I need to change?
  • Is there a different workflow I should follow?
  • Is there an extension that solves the problem?
like image 346
David Cruwys Avatar asked Oct 12 '25 10:10

David Cruwys


1 Answers

  1. in the find dialog enter your required regex search
  2. still in the find dialog execute command: editor.action.selectAllMatches (Alt+Enter)
  3. now all occurrences in editor are selected with multi cursor
  4. Alt+click a selection if you want to remove it from the set

If needed select a region of the file first. When opening the find dialog click the Find in Selection button (3 lines) first.

  1. in the find dialog enter your required regex search
  2. one of the following:
    • with the cursor in the Find dialog, execute editor.action.selectAllMatches (Alt+Enter)
    • click in the editor and execute command: Selection > Select All Occurrences editor.action.selectHighlights (Ctrl+Shift+L)
  3. now all occurrences in editor are selected with multi cursor
  4. Alt+click a selection if you want to remove it from the set

After you have done your edits and you still have multi cursors:

  • press as many times Esc till they are gone
  • click anywhere with the mouse in the editor not near a cursor

Some Emmet commands remove the multi cursor. So sometimes you have to do the selection again or change the order of your edits.

like image 90
rioV8 Avatar answered Oct 14 '25 11:10

rioV8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!