VS Code: Open File in New Tab (Easy Steps)
To open a file in a new tab in VS Code, simply click on the file in the Explorer sidebar or use the keyboard shortcut Ctrl+P (Windows/Linux) or Cmd+P (Mac) to search for and select the file. By default, VS Code opens files in a new tab, replacing the current one only if you have set the workbench.editor.enablePreview setting to false. This article explains the default behavior, how to customize it, and common issues you might encounter.
Default Behavior: Tabs vs. Preview
VS Code uses a tabbed editor interface, but it has a feature called Preview Mode (also known as Preview Editor). When you click a file in the Explorer, it opens in a preview tab. Preview tabs are italicized in the tab bar and are reused when you click another file—so the old file is replaced, not opened in a new tab. This is intentional to avoid cluttering the tab bar when you're just browsing files.
To keep a file permanently open in its own tab, double-click the file in the Explorer, or edit the file (make any change), or press Ctrl+K Enter (Windows/Linux) or Cmd+K Enter (Mac) to pin the tab. Pinning also prevents the tab from being closed accidentally.
How to Force Files to Always Open in a New Tab
If you prefer that every file opens in a new tab without the preview behavior, you can disable Preview Mode entirely. Follow these steps:
- Open the Settings: press
Ctrl+,(Windows/Linux) orCmd+,(Mac). - In the search bar, type
workbench.editor.enablePreview. - Uncheck the checkbox for Workbench › Editor: Enable Preview.
After disabling this setting, clicking a file in the Explorer will always open it in a new tab, and the tab will not be reused. You can also set workbench.editor.enablePreviewFromQuickOpen to false to prevent files opened via the Quick Open (Ctrl+P) from being preview tabs.
Using Keyboard Shortcuts to Open Files in New Tabs
Besides clicking, you can use keyboard shortcuts to open files efficiently:
- Ctrl+P (Windows/Linux) or Cmd+P (Mac): Opens the Quick Open dialog. Type the file name and press Enter. By default, the file opens in a preview tab unless you disable that setting.
- Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac) in the Quick Open dialog: Opens the file in a new tab (bypasses preview).
- Ctrl+Click (Windows/Linux) or Cmd+Click (Mac) on a file in the Explorer: Opens the file in a new tab to the side (split editor) rather than replacing the current tab.
- Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac): Opens the Command Palette, where you can type “Open File” to access the same file search.
Opening Files in a New Tab from the Command Line
If you’re comfortable with the terminal, you can open files in VS Code from the command line. The code command is installed when you install VS Code and add it to your PATH. To open a file in a new tab, simply run:
code path/to/file.txt
This opens the file in the current VS Code window, or a new window if none is open. To open multiple files, list them all: code file1.js file2.js. If you want to open the file in a new window, use the -n flag: code -n file.txt.
Common Problems and Fixes
Sometimes files don’t open in a new tab as expected. Here are common issues and solutions:
- File opens in the same tab (preview mode): This is the default. Double-click the file, or disable preview mode in settings as described above.
- Tab closes when you open another file: This is also preview behavior. Pin the tab (
Ctrl+K Enter) or disable preview. - File opens in a split editor instead of a new tab: This happens when you use
Ctrl+Click(orCmd+Click) on a file. To open in a new tab without splitting, just click normally (if preview is disabled) or useCtrl+Enterin Quick Open. - New tab opens but the old tab is still visible: This is normal. VS Code keeps multiple tabs open. You can close a tab by clicking the X on the tab or pressing
Ctrl+W(Windows/Linux) orCmd+W(Mac). - File doesn’t open at all: Check that the file exists and that you have permission to read it. Also ensure the file isn’t excluded by your settings (e.g.,
files.exclude).
Customizing Tab Behavior Further
VS Code offers several settings to fine-tune how tabs behave:
workbench.editor.showTabs: Set tofalseto hide tabs entirely (not recommended).workbench.editor.tabSizing: Controls how tabs are sized (e.g.,fit,shrink).workbench.editor.pinnedTabs: Allows you to pin tabs so they don’t close accidentally.workbench.editor.openPositioning: Set torightto open new tabs to the right of existing ones (default isright).
These settings are available in the Settings UI under Workbench → Editor.
Frequently Asked Questions
Why does VS Code open files in preview mode?
Preview mode is designed to keep the tab bar clean when you’re browsing files. It allows you to quickly click through files without creating a new tab for each one. The tab is marked with an italicized name and is reused when you click another file. If you edit the file or pin it, it becomes a permanent tab.
How do I make VS Code open files in a new tab by default?
Disable the workbench.editor.enablePreview setting. Go to Settings (Ctrl+,), search for “enablePreview”, and uncheck the box. This makes every file open in a new tab, and the tab will not be reused.
Can I open a file in a new tab without disabling preview?
Yes. Use Ctrl+Enter in the Quick Open dialog (Ctrl+P) to open the selected file in a new tab. Alternatively, double-click the file in the Explorer to open it as a permanent tab.
Why does my tab close when I open another file?
This is the preview behavior. The tab is in preview mode and gets replaced when you click another file. To keep it open, double-click the file, edit it, or pin it with Ctrl+K Enter. You can also disable preview entirely.
How do I open multiple files in new tabs at once?
You can select multiple files in the Explorer (using Ctrl+Click on Windows/Linux or Cmd+Click on Mac) and then press Enter to open them all. Or, from the command line, run code file1.js file2.js to open them in separate tabs.
Does VS Code have a limit on the number of tabs?
No, there is no hard limit. However, having too many tabs can make it hard to navigate. You can use Ctrl+Tab to cycle through tabs or use the tab bar’s overflow menu (the “…” icon) to see all open tabs.