microsoft / microsoft/vscode

Opening a non-existent file should not trigger "save dirty file" (Vim/Emacs-style "nothing changed, nothing to save")

Open
#327,076 3 comments 31 reactions 1 assignee Claimed by @lramos15 View on GitHub
feature-request
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

## Feature request

Add a setting that prevents a newly created, **empty and untouched** file from being treated as "dirty," so that closing it does not trigger a "Do you want to save?" prompt.

In Microsoft VSCode, if you open a new file ("code doesnotexist.txt` from the Terminal), make no changes, then try to exit, it asks if you want to save the file. Other editors, such as Vim and Emacs, do not ask to save the file. The logic of Vim and Emacs is that no changes (including creating the file) have happened, therefore there is nothing to save.

I'm requesting a feature to enable the behavior that Vim/Emacs uses.

## Current behavior

When you create a new file that has an associated path (for example `code newfile.txt` on a not-yet-existing file, or `File > New File‚` where you name it before it exists on disk), VSCode marks the editor as dirty **immediately**, before you type anything. Trying to close or exit then prompts you to save even though you made no changes and the file is empty.

> **Note:** A plain `File > New Untitled Text File` / `Ctrl+N` with no path does *not* have this problem -- it only becomes dirty once you type. This request is specifically about new files that carry an associated file path.

## Expected / desired behavior

Optionally match the behavior of editors like Vim and Emacs: if you create a new file, make no changes, and then quit, nothing was modified -- so there is nothing to save and no prompt should appear. The file should simply not be created on disk. As soon as you type any content, normal dirty-tracking and the save prompt would resume.

I'd propose an opt-in setting, e.g.:

```jsonc
// Whether a newly created empty file with an associated path is considered
// unsaved. When false, an untouched new file closes without a save prompt
// and is not written to disk (Vim/Emacs behavior).
"workbench.editor.untitled.dirtyWhenEmpty": true // default preserves today's behavior
```

Why?

Users coming from Vim/Emacs (and terminal-centric workflows) find the current prompt surprising: they opened a path, decided not to use it, and expect quitting to be a no-op. The reasoning "no changes were made, therefore there is nothing to save" is a well-established convention.

Notes on scope

This looks like a small, localized change. The dirty state for these editors is initialized in untitledTextEditorModel.ts (this.dirty = this.hasAssociatedFilePath || !!this.initialValue;), and there's already an "empty content / not dirty" path that is currently skipped when the editor has an associated file path. A setting could gate that behavior. Restored hot-exit backups should presumably remain dirty regardless, since they represent real unsaved content.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.