G S
G S

Reputation: 36818

How can I automatically save all on build in VS Code?

In Visual Studio when I trigger a build it automatically saves all files first. I want the same behavior in VS Code, but couldn't find a way to do it short of writing my own extension. Is there any simple method I'm missing?

Upvotes: 0

Views: 1248

Answers (2)

starball
starball

Reputation: 50105

If you're building using a task, then you can use the task.saveBeforeRun setting.

If you're using the CMake Tools extension, use the cmake.saveBeforeBuild setting.

You can also manually use one of the commands in the command palette with "save all" in their names (use whichever is appropriate for what you want), or the associated keyboard shortcut (you can also customize those keyboard shortcuts).

Upvotes: 0

Gama11
Gama11

Reputation: 34138

It's not exactly what you're asking, but will also accomplish what you want: you could enable the auto-save feature:

"files.autoSave": "afterDelay"

After using IntelliJ for a while, I managed to get rid of my habit of pressing Ctrl+S after every second typed-out word, for the most part (since it has auto-save by default). I was happy to find out that VSCode support this somewhat less stressful workflow too.


Other than that, there's also a Files: Save All command you've probably already found.

I'm actually not sure you can do this with the extension API right now - you can definitely trigger the "save all" command easily, but you'd need to be notified of when a build occurs, and I couldn't find any events for this. I think it will definitely be possible after #15179 is resolved though, which should allow extensions to participate in builds.

Upvotes: 2

Related Questions