Last updated: Apr 6, 2024
Reading time·7 min
To select all occurrences of the current selection:
Ctrl
+ Shift
+ L
keyboard shortcut on Windows and Linux.Cmd
+ Shift
+ L
keyboard shortcut on macOS.Once you press the keyboard shortcut, your cursor will be placed at the end of all occurrences of the selected text.
You can also use the "Select All occurrences of find Match" action using the Command Palette.
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.If you need to select all occurrences of the current word, without having to highlight it:
Ctrl
+ F2
keyboard shortcut on Windows and Linux.Cmd
+ F2
keyboard shortcut on macOS.If you need to select the next occurrence:
Ctrl
+ D
keyboard shortcut on Windows and Linux.Cmd
+ D
keyboard shortcut on macOS.If you need to undo the latest cursor selection:
Ctrl
+ U
keyboard shortcut on Windows and Linux.Cmd
+ U
keyboard shortcut on macOS.If you need to skip the current occurrence and add the next occurrence:
Ctrl
+ K
+ Ctrl
+ D
keyboard shortcut on Windows and Linux.Cmd
+ K
+ Cmd
+ D
keyboard shortcut on macOS.You can also select the next occurrence using the Command Palette.
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.You can also use the find functionality by pressing Ctrl
+ f
on Windows or
Linux or Cmd
+ f
on macOS.
You can press the arrows to go to the previous or the next match.
If you want to select all matches of the found text, press:
Alt
+ Enter
on Windows and LinuxOption
+ Enter
on macOSIf you need to find the matches in a selection of text (not all matches in the file):
Ctrl
+ f
(or Cmd
+ f
on macOS).The find functionality will only look for the text in the selected block.
The find functionality can also be used with a regular expression.
Ctrl
+ f
(Windows and Linux) or Cmd
+ f
on macOS and enable
regex search.You can enable regex search by clicking on the . *
icon.
Once you type in your regular expression, the matches will get highlighted.
Click on the screen to focus the main window.
Press Ctrl
+ Shift
+ L
(or Cmd
+ Shift
+ L
on macOS) to select
all matches.
Note that you have to click on the main code window for the selection to work.
You can also use the Select All Occurrences of find match keyboard shortcut
instead of Ctrl
+ Shift
+ L
.
The keyboard shortcut is:
Alt
+ Enter
on Windows and LinuxOption
+ Enter
on macOSThe keyboard shortcut selects all of the matches that were found using the
Ctrl
+ f
functionality.
You can then edit the selected occurrences, copy them, replace them etc.
If the Ctrl
+ Shift
+ L
shortcut doesn't work for you, use the command
palette instead.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You can use the Ctrl
+ H
(Windows and Linux) or Cmd
+ H
keyboard
shortcut if you need to replace all occurrences of the selected text.
Ctrl
+ H
(or Cmd
+ H
) to open the replace functionality.Here is a short clip that demonstrates the process.
If you need to only replace the occurrences of text in a part of a file:
Ctrl
+ H
(or Cmd
+ H
) to open the replace functionality.You can also use the Select All occurrences of find Match action to replace all occurrences of a selected text.
Ctrl
+ Shift
+ L
keyboard shortcut on Windows and Linux.Cmd
+ Shift
+ L
keyboard shortcut on macOS.If the Ctrl
+ Shift
+ L
keyboard shortcut doesn't work, you can also use
the Select All occurrences of find Match action via the Command Palette.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You can use the Ctrl
+ Shift
+ H
(Windows and Linux) or Cmd
+ Shift
+
H
(macOS) keyboard shortcut to replace all occurrences in all files.
You can also open the replace functionality by clicking on the magnifying glass in the left Activity Bar and expanding the arrow to show the field where the replacement text is entered.
The icon right next to the replacement field is used to replace all matches of the text in all files.
If you click on the three dots below the icon, you can select to only replace the text in specific files.
For example, if you enter *.ts
in the include
field, the matches are only
replaced in files that have a .ts
extension.
If you enter src/**/tasks
, the matches are only replaced in the
src/<anything>/tasks
directory.
The same approach can be used to exclude specific files or folders, you just add
the pattern to the exclude
field.
You can also replace all occurrences in specific files by hovering over the file in the results and clicking on the Replace all icon.
Here is a short clip that shows how to replace all occurrences in a specific file.
The same approach can be used to replace a single occurrence in a single file.
Hover over the line that you'd like to replace and click on the Replace button.
If you need to replace all occurrences using a regular expression:
Ctrl
+ h
keyboard shortcut on Windows and LinuxCmd
+ h
keyboard shortcut on macOS. *
icon to enable the Use Regular expression
functionality.The same approach can be used to replace all occurrences in all files using a regular expression:
Ctrl
+ Shift
+ H
keyboard shortcut on Windows and LinuxCmd
+ Shift
+ H
keyboard shortcut on macOS. *
icon to enable the Use Regular expression
functionality.I've also written an article on how to rename/refactor a variable name in VS Code.
You can learn more about the related topics by checking out the following tutorials: