djb
djb

Reputation: 1782

Visual Studio Code: Select each occurrence of find

I'm looking for a "select each occurrence of" something I'm trying to find. For example a file has a bunch of text that includes "abc", I type ctrl+f and type abc. I can either find the first one or the next one, but I would like to "multi-cursor" each one in the file.

I've already found the feature that lets me highlight text and ctrl+d to get the next that matches the selection, but if there's a hundred of these things - well that gets quite tiresome.

Upvotes: 160

Views: 152908

Answers (10)

Alex Barbu
Alex Barbu

Reputation: 107

You have 2 options

Search by the characters matching:

CMD+Shift+L to select all items that match a certain selection.

OR Search by using a regex pattern

  1. CMD+F to open the find menu in top right:

  2. Select the third option within the input (.*) and add the regex you want to match.

enter image description here

  1. CMD+Shift+L to select all items that match.

Upvotes: 4

Rodrigo Borba
Rodrigo Borba

Reputation: 1474

I know this thread is here for a while now, but I think this will be helpful:

This thread on Github talks exactly about it:
https://github.com/microsoft/vscode/pull/5715

Summary:

  1. Ctrl + F → Open find widegt.

  2. Alt + R → Turn on regex mode.

  3. Input search text → Regex text or normal text.

  4. Alt + Enter → Select all matches.

  5. Left arrow → Adjust cursors. (Ignore this step if you don't want to edit the selected text.)

  6. Edit text → Do what you want. (Ignore this step if you don't want to edit the selected text.)

  7. Shift + Home → Select modified text. (Ignore this step if you don't want to edit the selected text.)

  8. Ctrl + C → Copy selected text.

  9. Ctrl + N → Open a new tab.

  10. Ctrl + V → Paste.

Upvotes: 43

amdev
amdev

Reputation: 7442

Ctrl+Shift+L will select all occurrences of word in the document
BUT there is another way to selecting them growingly:
if you hit Ctrl+d it will selects the second match, it you hit Ctrl+d again it will match the third one and so on ....

Upvotes: 32

waz
waz

Reputation: 1253

For mac users:

Control + Command + G

^ + + G

Upvotes: 10

accimeesterlin
accimeesterlin

Reputation: 4718

For Mac User:

COMMAND + Shift + L Select all occurrences of the current selection

COMMAND + F2 Select all occurrences of the current word

Upvotes: 12

Eric D. Johnson
Eric D. Johnson

Reputation: 11737

How to Place Multiple Cursors at the End of All Your RegEx Finds

ALT + ENTER is what you're after (Thanks to Mark). Also note Rodrigo's answer has a nice step-by-step guide with explanations as well.

Full step by step example with keybindings

Note, this work with Azure Data Studio as well.

  1. CTRL + F (Find)
  2. ALT + R (toggleFindRegex command)
  3. '\d+' (what to look for)
  4. ALT + ENTER (add cursors; editor.action.selectAllMatches command)
    • CTRL + SHIFT + L (editor.action.selectHighlights command) also works here
  5. ESC (closeFindWidget command)

Now the following text should have four blinking cursors (at the daggers 🗡), where you can edit to your 🧡s content!

INSERT INTO [dbo].[Location] (key, longName, shortName, oldRegion, contactId, email, city, state, zip, isActive)
VALUES
('GEORG','Georgian College','GEORG','1A','1271'🗡,'[email protected]','Barrie','ON','L4M 3X9','1'🗡),
('LOYAL','Loyalist College','LOYAL','2A','1271'🗡,'[email protected]','Belleville','ON','K8N 5B9','0'🗡)
-- etc.

To find this or similar keybindings open the Keyboard Shortcuts and search for findWidget for commands used with CTRL + F, or searchViewlet for commands used with CTRL + SHIFT + F.

Upvotes: 1

PolarisTLX
PolarisTLX

Reputation: 349

Ctrl+F2 is what worked for me for VSCode on Windows 10.

While Ctrl+Shift+L just opened some Language selector.

Upvotes: 5

Amal
Amal

Reputation: 461

If you are searching in a single file, use simple search using Ctrl+F, then even if you close the search box, simply keep pressing F3 to go to next match and so on. F3 just repeats previous search and selects your next match.

Upvotes: 1

Jon G
Jon G

Reputation: 1415

Alt+Enter Select all occurrences of find match

editor.action.selectAllMatches

This has the added benefit of working with Regular Expression searches, since selecting occurrences of a word of a selection cannot leverage the Regex functionality.

Upvotes: 129

Dauren Akilbekov
Dauren Akilbekov

Reputation: 5025

Ctrl+Shift+L Select all occurrences of current selection

editor.action.selectHighlights

Ctrl+F2 Select all occurrences of current word

editor.action.changeAll

Please refer for more information here.

Upvotes: 250

Related Questions