Is it possible to automatically save all changed files before build? It's a bit tedious to press Ctrl+s and then Ctrl+Shift+b all the time.
4 Answers
If you don't need to build but rather run the file, then you can adjust the Code Runner extension settings by adjusting your user settings. Settings can be accessed in file > preferences > settings
(or with Ctrl+comma.)
To save the current file before running add the line below to your User Settings:
"code-runner.saveFileBeforeRun": true,
or to save all files before running, add this line:
"code-runner.saveAllFilesBeforeRun": true,
I also added this shortcut key(keybinding) to file > preferences > keyboard shortcuts > keybindings.json
{
"key": "ctrl+enter",
"command": "code-runner.run"
},
Now I can just hit Ctrl+Enter and all the magic happens.

- 14,260
- 6
- 48
- 57
-
1I did a screen record: [link](https://imgur.com/2P3iPdA) – Shub Jun 23 '23 at 11:12
This feature seems to have been implemented now:
Goto: File > Preferences > Settings
In "Search Settings" box at top, enter "Save".
Multiple matches will be listed.
Scroll down to: Task: Save Before Run and select: Always save all editors before running
Before leaving, take a moment to review some of the other language-specific options to see if any of them is of interest.

- 689
- 1
- 12
- 25
-
1This does not work reliably. For example, it doesn't work with Python, as far as I can tell. – Oscar Sep 28 '22 at 00:53
-
As of recent, for some reason this setting is already enabled for me but when i run a python file it opens a file dialog asking me to save it manually, which is incredibly annoying. makes my blood boil. – Spiceinajar May 10 '23 at 14:23
Turns out there is an open feature request for this - https://github.com/Microsoft/vscode/issues/21342
The reverse thing (build on save) can be done, for example, with extension "Trigger Task on Save" (https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.triggertaskonsave)

- 6,217
- 8
- 34
- 62
-
4As of sometime in 2017, running tasks does automatically save all: https://github.com/Microsoft/vscode/issues/21342#issuecomment-343141199 The issue will remain open until the behavior can be controlled: https://github.com/Microsoft/vscode/issues/21342#issuecomment-432593879 – Cameron Tacklind Nov 04 '18 at 01:35
Setting files.autoSave
to afterDelay
is probably your best alternative. You can combine it with decreasing autoSaveDelay
so that files are autosaved quickly without you having to do anything.
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 100,

- 42,571
- 24
- 140
- 158
-
1Since I'm using an extension to reformat my code after save, using autosave could be a pain because code will literally slip away from my cursor. – Amomum Apr 27 '17 at 11:51