Close the active Tab or all Tabs in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
4 min

banner

# Table of Contents

  1. Close all tabs in Visual Studio Code
  2. Close all tabs only in a specific editor group
  3. Close all tabs except the current tab in VS Code
  4. Close the active tab in VS Code
  5. Using other close tab commands

# Close all tabs in Visual Studio Code

To close all tabs in Visual Studio Code:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type close all and select View: Close All Editors.

close all tabs

Here is a short clip that demonstrates the process:

vscode close all editors

The same approach can be used to close all tabs without saving. When you get prompted, select Don't save.

select dont save

You can also use a keyboard shortcut to close all tabs:

  • On Windows and Linux, press: Ctrl+K Ctrl+W
  • On macOS, press: Cmd+K Cmd+W

You first press Ctrl+K, then release and then press Ctrl+W.

You can view keyboard shortcuts for the Close All command in this table in the docs.

If you hover over the key combination in the Key column, the keyboard shortcuts for all operating systems are displayed.

# Close all tabs only in a specific editor group

If you need to close all tabs only in a specific editor group (when you have split screen), select the View: Close all Editors in Group instead.

close all tabs in group

The command only closes the editors (or tabs) in the selected part of the screen.

# Close all tabs except the current tab in VS Code

If you need to close all tabs except the current one:

  1. Right-click on a tab.
  2. Select Close Others.

close all tabs except current

Here is a short clip that demonstrates the process.

close all tabs except current

The command doesn't have a keyboard shortcut by default.

If you want to set one:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for close other and double-click on the View: Close Other Editors in Group row.

close all tabs except current

You can also click on the plus icon to set a keyboard shortcut.

  1. Specify your preferred key combination and hit Enter to confirm.

For example, I use Ctrl + F4.

set custom keyboard shortcut close other tabs

# Close the active tab in VS Code

If you need to close a single tab, use the following keyboard shortcut:

  • Ctrl + W on Windows and Linux.
  • Cmd + W on macOS.

vscode close single tab

You can also use the command palette to close the active tab in VS Code.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Close editor and select View: Close Editor.

close active tab using command palette

If you need to change the keyboard shortcut for the command:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for close active and double-click on the row.

close active tab keyboard shortcut

  1. Specify your preferred key combination and hit Enter to confirm.

# Using other close tab commands

You can also use other Close Tab commands by right-clicking on a tab.

right click close commands

As shown in the screenshot, there are multiple options:

  • Close - close the currently active tab.
  • Close Other - close all tabs except the current one.
  • Close to the Right - close all tabs to the right of the current tab.
  • Close Saved - close all tabs that are saved.
  • Close All close all tabs.

For example, if you only want to close the tabs to the right of the current one, right-click on the given tab and select Close to the Right.

close tabs to the right

Similarly, if you only want to close the saved tabs, select the Close Saved command.

close saved tabs

To view all available close tab commands:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type close and scroll through the list of options.

view all close tab commands

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.