38

Env

  • Ubuntu 16.04

  • Visual Studio Code v 1.2.1

Problem

I can search occurrences in all files by Ctrl + Shift + F

However, I can't find a way to search and replace occurrences in all files.

Is this a missing(or hidden) feature in Visual Studio Code.

aspdeepak
  • 2,640
  • 2
  • 32
  • 37
  • see https://msdn.microsoft.com/en-us/library/139eef4h.aspx – piyushj Jun 29 '16 at 12:13
  • Possible duplicate of [Visual Studio Code Replace multiple files at once](http://stackoverflow.com/questions/32897659/visual-studio-code-replace-multiple-files-at-once) – Ivan Zlatev Jun 29 '16 at 12:15
  • @IvanZlatev mine is about replacing single word across multiple files. The other one is about replacing multiple lines in multiple files. – aspdeepak Jun 30 '16 at 07:44

5 Answers5

52

Visual Studio Code v 1.3.0++ has this feature:

Replace functionality can be accessed:

  • In the Search View by expanding the Search textbox
  • Using Ctrl + Shift + H, from the Edit | Replace in Files menu
  • Using Replace in Files command in the Command Palette

Global Search and replace

MD Ashik
  • 9,117
  • 10
  • 52
  • 59
aspdeepak
  • 2,640
  • 2
  • 32
  • 37
  • 9
    how do you specify where to apply the changes (eg: current opened file)? – zok Oct 12 '17 at 15:54
  • 1
    And don't forget to escape any slashes that precede intended capture groups. So if for example you are refactoring `App\...` to `App\Models\...` across files, then your replacement using search string `\bApp\\([A-Za-z]*\b)` will be `App\Models\\$1` – Damilola Olowookere Dec 11 '19 at 23:41
11

VS Code also supports capturing groups when using regex, captured groups (using parenthesis) can be referenced with $1 for the first match, $2 the second etc. $0 returns the complete match.

Reversing "abc"

Reversing direction of "abc"

Appending "def"

Appending "def"

robstarbuck
  • 6,893
  • 2
  • 41
  • 40
  • This is what I have been looking for as I do not wanted to replace, but more like append/extend, keeping the original. By referencing the capture groups, I could easily append across multiple files, where some of the words were only matched by pattern and not exact string. – Bence Kaulics Nov 16 '20 at 12:46
3

It's currently not possible to replace in all files. The good news is it's part of the June Iteration Plan. The feature has already passed a couple of tests. So it will be probably released in July 2016.

Wosi
  • 41,986
  • 17
  • 75
  • 82
1

As an enhancement, VSCode 1.70 supports search and replace in all selected files, solving the 2018 issue 47166 "Make search tree context menu multiselect-aware".

See PR 154847 (available today in VSCode insiders)

Make search tree context menu multiselect-aware

When multiple entries are selected, if someone removes/replaces on one selected item, it happens to everything.

Note: if a whole file (uses Replace All) and entry (just uses Replace) are both selected at once and either Replace or Replace All is used, whatever replace action is valid for all selected item will run.

For example, if a file and entry are all selected and the Replace button is selected on the entry, then Replace All will be run on the file and Replace will be run on the entry.

https://user-images.githubusercontent.com/31675041/178347470-174e2b08-307e-47ac-a0c2-0a726738b5c5.gif

Example:

https://camo.githubusercontent.com/52ffd85f2166bb5580d7be74b527423801c36d4f58a67eefd1b0f77d26451cc4/68747470733a2f2f692e6779617a6f2e636f6d2f64636462376338613066643836323930383339663733636630376436356330322e676966

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

All File:

Search =  Ctrl + Shift + F 
Replace =  Ctrl + Shift + H 

One File:

Search =  Ctrl + F 
Replace =  Ctrl + H 
Shaiful Islam
  • 335
  • 2
  • 12