Knowing how to close VS Code using a keyboard shortcut can save time when you are switching projects, finishing a coding session, or clearing your screen. The right shortcut depends on what you want to close: the current editor tab, the VS Code window, or the entire application. It also varies slightly between Windows, Linux, and macOS. This guide explains the common keyboard shortcuts, what each one does, and how to find or change them if they do not work on your computer.
Quick Answer: VS Code Keyboard Shortcuts to Close
Use these default shortcuts in the VS Code desktop application:
-
Close the active editor:
Ctrl+Won Windows and Linux, orCmd+Won macOS. -
Close the VS Code window:
Ctrl+Shift+Won Windows and Linux, orCmd+Shift+Won macOS. -
Quit VS Code on macOS:
Cmd+Q. -
Close a window using the operating system:
Alt+F4on Windows and many Linux desktop environments.
These shortcuts have different effects. Closing an editor usually leaves the project and application open. Closing a window dismisses that VS Code window, while quitting exits the application. If you are unsure, save your work before using a shortcut that closes a window or quits VS Code.
Close the Current Editor Tab in VS Code
To close only the file you are currently viewing, press Ctrl+W on Windows or Linux. On a Mac, press Cmd+W. This runs the Close Editor command, which closes the active editor tab without necessarily closing the VS Code window or your project.
This is the best shortcut when you have finished editing one file and want to keep working in the same workspace. If other editor tabs remain open, VS Code switches to another tab. If the active file is the last open editor, the window may show another view or an empty editor area, depending on your layout and settings. The application itself generally stays open.
If the file has unsaved changes, VS Code prompts you to save, discard, or cancel. Choose Save to keep your edits, Don’t Save to discard them, or Cancel to return to the file without closing it. You can also save first with Ctrl+S on Windows or Linux, or Cmd+S on macOS.
Be aware that Ctrl+W is also a common shortcut for closing a browser tab. If you are using VS Code in a web browser rather than the desktop app, the browser may handle the shortcut and close its tab. In that case, check your browser’s shortcut behavior and consider using VS Code’s Command Palette to close the editor.
Close a VS Code Window with the Keyboard
To close the current VS Code window while keeping the application available, use Ctrl+Shift+W on Windows or Linux. On macOS, use Cmd+Shift+W. This shortcut closes the window and its workspace, rather than merely closing the active file.
If you have several VS Code windows open, this command closes only the window you are currently using. Other windows remain open. This is useful when you have separate projects in separate windows and want to finish with just one of them.
Before the window closes, VS Code may ask what to do with unsaved files. Save any changes you need to keep. If the shortcut does not work, the keybinding may have been customized, or another application or desktop environment may be intercepting it. You can look up the current binding in VS Code’s Keyboard Shortcuts editor.
Quit the Entire VS Code Application
Closing a window and quitting an application are not always the same action. This distinction is especially important on macOS, where closing the last window with Cmd+W can leave VS Code running. To quit VS Code on a Mac, press Cmd+Q. You can also use the VS Code application menu and choose Quit Visual Studio Code.
On Windows, Alt+F4 closes the active VS Code window. If it is the only open window, that will usually end your VS Code session. On Linux, Alt+F4 is also a common window-closing shortcut, though behavior can vary by desktop environment. To ensure you are using VS Code’s own command, open the Command Palette and search for a quit command.
When quitting, VS Code may ask you to save modified files or confirm an action. Do not force-close the application if you have unsaved work. A normal quit gives the editor a chance to prompt you and close cleanly.
Use the Command Palette to Close VS Code
The Command Palette is a reliable option when you cannot remember a shortcut or suspect that your keybindings have changed. It lets you search for commands by name and run them without needing to know the assigned keys.
- Open the Command Palette with
Ctrl+Shift+Pon Windows or Linux, orCmd+Shift+Pon macOS. - Type Close Editor to find the command for the active file.
- Type Close Window to find the command for the current VS Code window.
- Search for Quit to find an application exit command, if one is available for your platform.
- Select the desired command and press
Enter.
The Command Palette is particularly helpful if you are using a different keyboard layout, working on a remote desktop, or using a custom keybinding profile. It also helps you confirm the command name before changing shortcuts.
Find or Change the Close Shortcut
VS Code allows you to inspect and customize keyboard shortcuts. Open Keyboard Shortcuts by pressing Ctrl+K, then Ctrl+S on Windows or Linux. On macOS, use Cmd+K, then Cmd+S. You can also open the Command Palette and search for Preferences: Open Keyboard Shortcuts.
In the Keyboard Shortcuts editor, search for commands such as Close Editor, Close Window, or Quit. The results show the current keybinding, if one is assigned. To change a binding, select the pencil icon beside the command, press your preferred key combination, and confirm it.
Choose a shortcut that is easy to remember but does not conflict with a command you use often. If VS Code reports a conflict, review the competing commands before accepting the change. You can remove a custom binding or restore a default one from the same editor.
What Happens to Your Files and Workspace?
Closing VS Code does not normally delete files from your computer. Closing an editor removes the file from the current editor area, while closing a window dismisses that workspace window. Your project files remain in their folders unless you explicitly delete or move them using a file-management command.
VS Code may reopen your previous folders and editor tabs the next time you start it, depending on your startup settings. That behavior is separate from saving the files themselves. Saving writes changes to disk; reopening a workspace restores your working context. If you want a file’s edits to persist, save it before closing.
Unsaved changes are the main risk to consider. A modified file is usually marked in its tab, and VS Code prompts you before discarding edits. Read the prompt carefully, especially if you are closing multiple windows or quitting the application.
Troubleshooting VS Code Close Shortcuts
If a keyboard shortcut does not close the expected item, start by checking which part of VS Code has focus. The shortcut may be handled by a terminal, an extension, your operating system, or a browser instead of the editor. Try clicking a file tab and repeating the shortcut, or run the matching command through the Command Palette.
- The wrong tab or window closes: Confirm whether you pressed the editor shortcut or the window shortcut.
- Nothing happens: Search for the command in Keyboard Shortcuts and check whether it has a keybinding.
- A browser tab closes: You may be using VS Code for the Web, where the browser can claim common shortcuts.
- A prompt appears: Review the unsaved changes and select the option that matches what you want to do.
- Your shortcut conflicts with another command: Change the keybinding or use the Command Palette instead.
Keyboard behavior can differ with external keyboards, international layouts, remote connections, and customized settings. If a shortcut seems unavailable, checking the command’s current binding is more dependable than assuming every installation uses identical settings.
Close VS Code with the Keyboard: The Bottom Line
For most users, the key distinction is simple: use Ctrl+W on Windows or Linux, or Cmd+W on macOS, to close the active editor. Use Ctrl+Shift+W or Cmd+Shift+W to close the current VS Code window. On macOS, use Cmd+Q when you want to quit the application completely; on Windows and many Linux systems, Alt+F4 closes the active window.
Save important edits before closing, and use the Command Palette or Keyboard Shortcuts editor whenever you need to confirm a command. Once you know whether you want to close a file, a window, or the whole application, closing VS Code with a keyboard becomes quick and predictable.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.