Jeffery Tang
Jeffery Tang

Reputation: 403

Select all occurences of all selected keywords in VS Code

I know in visual studio code you can select a keyword (e.g. "bob") and press Command+Shift+L to select all instances of it. But what if I currently have two different keywords selected with the alt key (e.g. "bob" and "alice"), Command+Shift+L only selects all "bob" or all "alice". How do I get all instances of both selected in this case? Is regex the only way?

Upvotes: 0

Views: 27

Answers (2)

Mark
Mark

Reputation: 182541

There is an easy way to do that with an extension I wrote, Find and Transform. Make this keybinding in your keybindings.json:

{
  "key": "alt+q",            // whatever keybinding you want
  "command": "findInCurrentFile",
  "args" : {
      // the description is optional
      "description": "This will select all matches of the selected items"
  }
}

When using the extension with no arguments, like find, replace, etc. it will automatically find all matches of any selected terms or pieces of text - it doesn't matter how many there are.

You don't even need to select the whole word, a cursor in a word will select that whole word and any other matches.

select All matches of selected text

select all matches of words at cursors

Upvotes: 1

rioV8
rioV8

Reputation: 28783

Yes regex is the way.

  • in Find dialog enable regex search: .* button
  • in Find dialog enter the regex: \b(bob|alice)\b
  • in Find dialog press: Alt+Enter

Upvotes: 1

Related Questions