skip to Main Content

I am using the VS Code 1.82.2 on Mac.

Recently, I had to open 5 files and replace the same text within all 5 files, which I did using Cmd + Shift + F buttons. However, what I found is that when you click the ‘Replace all’ button and see the dialogue to confirm the action, clicking the ‘Replace’ button will change and save all files in one click.

How can I disable the auto-save feature as I’d rather save all files manually or in one click (Save All) myself?

"files.autoSave" is set to "off". I expect all files to remain unsaved after ‘Replace all’

2

Answers


  1. Hm. At the time of this writing, I’m not aware of there currently being a way to change this behaviour. Actually, it used to be that replacing things using the Search View would open every single file, make the change, and leave those files unsaved, but several users found this annoying. The relevant historical issue ticket is Feature Request: Find in files>Replace All option to save and close #14554. As a result of that issue ticket, the behaviour was changed in the March 2018 release by commit 0376136.

    There is talk about tweaking the behaviour- particularly, making it so that the changes aren’t automatically saved if only one file is affected: Don’t autosave when replacing in single file
    #46983
    , which I recognize is not what is being asked about here. Though interestingly, multiple people suggest / ask in that issue ticket for there to be the ability to choose whether to save the changes, or leave them unsaved: here, here, here (this one is interesting because it suggests more configuration options), here, here. I suggest that you give those comments a thumbs up reaction each, and subscribe to the issue ticket to get notified about discussion and progress. Please avoid piling on noisy small comments like "+1 for X’s comment" (just use thumbs up reactions for that).

    Login or Signup to reply.
  2. When using the multifile replace dialog box, rather than applying "replace all", you can see a preview of the replace result right below in the same box.

    From there, you can review any single proposed change and either apply it or skip it. You can also apply "replace all" to any specific file.
    If you click on a specific proposed change, you’ll see a diff view showing you the result of the change in the context of the entire file, yet unsaved.

    Not only that, but if you remove a specific proposed change by clicking the "X" next to it, and then apply "replace all" to the file it’s related to, it’ll replace all occourences in that file except the skipped ones.

    All those preview & review methods provided, I think it should serve almost any usecase of "replace without saving".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search