VS Code Files and Auto Save Cheat Sheet
Sidebar
Programming ยท VS Code Files and Auto Save Cheat Sheet
The files.* settings and their closest relatives: saving, tidying files on save, line endings and encoding, recovery, and which files are shown or watched. Exact ID, what it does, and its default. Sheet 2 in the VS Code series; sheet 1 covers editor.*.
Auto Save
files.autoSaveoff (default), afterDelay, onFocusChange, onWindowChangefiles.autoSaveDelayMilliseconds to wait with afterDelay (default 1000)files.autoSaveWorkspaceFilesOnlytrue: only auto-save files inside the open workspace (default false)files.autoSaveWhenNoErrorstrue: skip auto save while the file has errors (default false)File > Auto SaveMenu toggle that switches auto save on and off without opening settingsCtrl+S / Ctrl+K SSave the current file / Save All (Windows/Linux)Tidy Up on Save
files.trimTrailingWhitespaceRemove spaces at the end of lines on save (default false)files.insertFinalNewlineEnsure the file ends with a newline (default false)files.trimFinalNewlinesRemove extra blank lines at the end of the file (default false)files.trimTrailingWhitespaceInRegexAndStringstrue (default): trailing-space trimming also touches regexes and stringseditor.formatOnSaveRun the formatter when you save (default false)editor.formatOnSaveModefile (default), modifications, modificationsIfAvailable: whole file or only changed lineseditor.codeActionsOnSaveFixes on save, e.g. { "source.fixAll": "explicit" }Line Endings & Encoding
files.eolDefault line ending for new files: "\n", "\r\n" or "auto" (default auto)files.encodingCharacter encoding used when reading and writing files (default utf8)files.autoGuessEncodingtrue: try to detect a file's encoding when opening it (default false)files.candidateGuessEncodingsEncodings to try first when guessing (default none)Status bar: CRLF / LFClick to convert the current file's line endingsStatus bar: UTF-8Click, then Reopen with Encoding or Save with EncodingHot Exit & Recovery
files.hotExitoff, onExit (default), onExitAndWindowClose: remember unsaved files between sessionsfiles.restoreUndoStackRestore undo history when a file reopens (default true)workbench.localHistory.enabledKeep automatic snapshots of saved files (default true)workbench.localHistory.maxFileEntriesSnapshots kept per file (default 50)workbench.localHistory.maxFileSizeLargest file, in KB, that gets snapshots (default 256)Timeline viewExplorer panel listing a file's local history; right-click an entry to compare or restoreHiding, Watching & Protecting Files
files.excludeGlob patterns hidden from the Explorer; default hides .git, .svn, .hg, .jj, .DS_Store, Thumbs.dbfiles.watcherExcludeFolders VS Code does not watch for changes; the default skips .git/objects and similarfiles.watcherIncludeExtra folders to watch (default none)files.associationsMap patterns to languages, e.g. { "*.cmd": "bat" } (default none)files.readonlyIncludeGlob patterns of files to open read-onlyfiles.readonlyExcludeExceptions to files.readonlyIncludefiles.enableTrashtrue (default): deleting from the Explorer moves files to the Recycle BinConflicts, Timeouts & Dialogs
files.saveConflictResolutionaskUser (default) or overwriteFileOnDisk when the file changed elsewherefiles.participants.timeoutHow long format/fix-on-save may run, in ms (default 60000)files.defaultLanguageLanguage assigned to new, untitled files (default: none, you choose)files.dialog.defaultPathFolder where Open/Save dialogs start (absolute path)files.simpleDialog.enabletrue: use VS Code's own file dialog instead of the system one (default false)A Reasonable Starter Set (my suggestions, not defaults)
"files.autoSave": "onFocusChange"Saves when you switch away, and still runs format on save"files.trimTrailingWhitespace": trueNo invisible trailing spaces in commits"files.insertFinalNewline": trueA final newline keeps diffs and Unix tools happy"files.trimFinalNewlines": trueNo pile of blank lines at the end"files.eol": "\n"LF for new files, common for cross-platform projects"files.exclude": { "**/__pycache__": true }Hide clutter you never open[markdown]Override with { "files.trimTrailingWhitespace": false }, because two trailing spaces mean a line break in MarkdownWhy didn't Format on Save run? Check which kind of save it was
Format on save is skipped for the timed auto save ("files.autoSave": "afterDelay"), but it does run when you press Ctrl+S and for the onFocusChange and onWindowChange auto saves. If you want auto save and formatting, use onFocusChange. Related: editor.codeActionsOnSave values are explicit (only on manual saves), always, or never.