Visual Studio Code: Select each occurrence of find
Asked Answered
K

10

152

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.

Kaph answered 14/3, 2016 at 15:51 Comment(1)
on a mac, after find, you need ⌥⮐Boiling
C
234

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.

Canalize answered 15/3, 2016 at 10:35 Comment(6)
Thanks for the answer @dauren-akilbekov . Is there any difference between Ctrl+Shift+L and Ctrl+F2?Pisci
Is there a case sensitive version of Ctrl + Shift + L ?Atticism
@jokerster You can toggle case sensitivity in editor by alt+c (while the editor where the text you want to match is focused), this will change the behavior of various selection/find tools.Floppy
For large files, there is a limit of 1000 "cursors". So, you may have to modify you text more than once.Neurotomy
The number of cursors has been limited to 10000.Morph
On Mac, it'll be Shift-Cmd-L – official reference cheatsheet for macOSBlois
G
121

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.

Goldin answered 13/2, 2017 at 20:42 Comment(2)
This is the answer I needed, because this allows me to select a subset of matches within an already selected block.Consummation
VS Code needs a UI button for this! Vote for it here: github.com/Microsoft/vscode/issues/20453Ratafia
G
41

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.

Gissing answered 10/7, 2020 at 12:19 Comment(0)
G
31

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 ....

Gallion answered 30/5, 2018 at 15:39 Comment(5)
In mac Ctrl + d is duplicating the lineFeminine
It is Cmd+d in macTympan
Is there a similar shortcut like CTRL+D but for Visual Studio (not VS Code) ?Schoenfeld
to be honest, i never used visual studio code ever , sorryGallion
That's what I've been looking for!Alger
M
12

For Mac User:

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

COMMAND + F2 Select all occurrences of the current word

Marlin answered 1/8, 2018 at 19:22 Comment(1)
If one of the default shortcuts isn't working (or is performing another action), this can be because an extension you've installed has overridden the default shortcut. You can establish which extension by opening Keyboard Shortcuts with Ctrl+K, Ctrl+S and in the search box at the top, type Ctrl+Shift+L. There you should see what's using that keyboard combination and you can remove or change it as desired.Rettke
D
10

For mac users:

Control + Command + G

^ + + G

Dihybrid answered 20/3, 2018 at 2:40 Comment(0)
P
5

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

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

Protolithic answered 3/7, 2019 at 4:8 Comment(0)
E
3

On Mac:

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

enter image description here

  1. Select the third option within the input and add the regex you want to match.

  2. Ctrl+Shift+L to select all items that match.

Exhort answered 30/12, 2022 at 11:57 Comment(0)
L
1

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.

Libbie answered 28/3, 2018 at 16:36 Comment(1)
Not really what I was looking for - I wanted to select all occurrences at once to edit them all at once.Kaph
M
1

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.

Mikey answered 21/9, 2023 at 17:4 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.