Question

When I do a global search/replace in a project, Sublime will automatically open all the files involved, and not save them. I then have to manually save every single file.

Is there a way to have Sublime automatically save all the changes that have been done, and not open the files that where not previously open?

Thanks in advance for anyone who can help me with this.

http://www.sublimetext.com/forum/viewtopic.php?f=3&p=40348

Was it helpful?

Solution

I think it's Option + Command + S(Mac) or Command + Alt + S(Win).

OTHER TIPS

Just performed a similar task with the free Visual Studio Code. Replace in Files without opening files and fast. Just made 60k changes in just a few minutes.

Robust if awkward.

While it doesn't change the fact that Sublime Text doesn't seem to be the best tool for this job, here's a practical workaround procedure I've come to rely on. It's reasonably slow but painless if done correctly. Memory consumption impact seems negligible, if you're wondering. The ballpark of my use cases is up to about 10k files in up to a handful of minutes on a mediocre memory-cramped machine using Sublime Text 3.2.2 (3211) on Windows 10 Pro x64.

Requirements

You'll need the package SideBarEnhancements to be installed.

…which in turn relies on Sublime Text 3 or newer as of writing this.

Procedure

  1. (Could probably be deferred until step 3.) You add the directory A that you're going to operate on to the project sidebar.
  2. You initiate your batch replacement operation over numerous files inside directory A.
  3. Sublime Text takes its time to open numerous tabs belonging to directory A recursively and perform replacement in each.
  4. You right-click on the directory A in the project sidebar to bring up its context menu and choose "Save Views".
  5. Sublime Text takes its time to save each tab belonging to directory A recursively.
  6. You right-click on the directory A in the project sidebar to bring up its context menu and choose "Close Views".
  7. Sublime Text takes its time to close all tabs belonging to directory A recursively.

Disclaimers

Warning

Do not make the mistake of skipping step 3 or you'll effectively become stuck in a GUI loop of writing confirmation dialogs defaulting to "Yes" for however many thousands of files you're operating on.

If you decide to abort operation between steps 2 and 3 — your best course of action, is to back the files up on disk, proceed with the outlined procedure and then restore the backup.

Caution

All of the tabs belonging to the directory you'll operate on will be closed by the end of this procedure. If you need a substantial portion of them to remain open throughout replacement — consider organizing the files contained into a sub-directory structure conducive to cherry-picking.

General advice

As a rule of thumb, before proceeding with this procedure, it would be wise to check if the required context menu entries are in fact present (greyed out or not) in your combination of editor+package versions. And to be on the safe side, you might want to back up your data and Sublime Text session before massive operations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top