Close or reopen a VS Code editor without losing track of the file

Command-W closes the active editor; Shift-Command-T reopens a closed editor. Keep closing an editor separate from deleting a file.

Scope
Visual Studio Code · Current vendor documentation checked 3 November 2026; no running-app compatibility test is claimed.
Keyboard and customization
Documented Mac defaults; punctuation and function keys depend on keyboard layout and hardware.. User bindings, app versions, focused controls and installed extensions can change a command. Inspect the active app menu or its shortcut editor when a listed combination differs.
Review basis
Documentation reviewed 2026-11-03 by Codex — primary-documentation and editorial review; no hands-on runtime test. These bindings were not tested in a running app for this guide.

Read the active tab first

When several files are open, the highlighted editor tab identifies the context affected by a close command. A preview editor and a pinned editor can also have different persistence behaviour. Check which file is active before closing it, especially after navigating through search results or opening a definition in another group.

Respect unsaved-change prompts

Closing a view does not mean you should discard its changes. If the editor asks what to do with unsaved content, read the options and save or cancel deliberately. Reopening a closed editor is a navigation convenience, not a backup strategy and not a guarantee that discarded changes can be recovered.

Practise with two saved files

Open two harmless files, close the active editor and reopen it. Observe the filename and group it returns to. Then compare closing all editors with closing one, using the menu labels to verify the scope. The distinction becomes useful when cleaning up a crowded workspace without changing repository contents.

Documented commands for this workflow

Scroll the table sideways to see every column.

ActionKeysWhen to use it
Close the active editorCommand-WApplies to the active editor context; handle any save prompt deliberately. ↗
Reopen a closed editorShift-Command-TRestores a recently closed editor rather than undoing file deletion. ↗
Close all editorsCommand-K, then Command-WA chord with broader scope; inspect unsaved work first. ↗

Sources and corrections

Found a mismatch? Email pashaseenainc@gmail.com with your app version, macOS version, keyboard layout and the command. Please leave personal document names out.

Keep going

Right there when you need it.

Keep a compact shortcut reference in your Mac’s menu bar.

Explore the native Mac app