How to switch to the Previous/Next Tab in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
6 min

banner

# Table of Contents

  1. How to switch to the Previous/Next Tab in VS Code
  2. Switching tabs in order of last use
  3. Updating your Keyboard shortcuts for navigating tabs
  4. Switching to a specific tab by Index in VS Code
  5. Switch to the previous/next group in VS Code
  6. Opening the previous editor from history

# How to switch to the Previous/Next Tab in VS Code

On Windows and Linux:

  • Use Ctrl + PageDown to switch to the next tab.
  • Use Ctrl + PageUp to switch to the previous tab.

On macOS:

  • Use Cmd + Option + Right arrow key to switch to the next tab.
  • Use Cmd + Option + Left arrow key to switch to the previous tab.

switch to previous next tab

An easy way to view the keyboard shortcut for your operating system is to:

  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 View: Open Previous Editor and check the keyboard shortcut.
  2. Type View: Open Next Editor and check the keyboard shortcut.

find keyboard shortcut for switching tabs

If you use the VSCodeVIM extension, use:

  • g t to switch to the next tab.
  • g T to switch to the previous tab.
  • N g t to switch to a tab by index, e.g. 1 g t or 2 g t.

# Switching tabs in order of last use

If you need to switch tabs in order of last use:

On Windows and Linux:

  • Use Ctrl + Tab to switch to the previous recently used editor in the group.
  • Use Ctrl + Shift + Tab to switch to the least recently used editor in the group.

On macOS:

  • Use Cmd + Tab to switch to the previous recently used editor in the group.
  • Use Cmd + Shift + Tab to switch to the least recently used editor in the group.

switching tabs in order of last use

The keyboard shortcut doesn't switch to the next tab, it switches to the most recently used tab.

# Updating your Keyboard shortcuts for navigating tabs

If you want to use the Ctrl + tab and Ctrl + Shift + tab to switch through tabs in order, you have to update your keyboard shortcuts.

  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. Type view open previous editor and double-click on the View: Open Previous Editor row to edit the keyboard shortcut.

You can also click on the pencil icon to set up a new keyboard shortcut.

view open previous editor shortcut

  1. Press Ctrl + Shift + Tab and then hit Enter to confirm.

If you are on macOS, press Cmd + Shift + Tab instead.

  1. Type view open next editor and double-click on the View: Open Next Editor row to edit the keyboard shortcut.

view open next editor shortcut

  1. Press Ctrl + Tab and then hit Enter to confirm.

If you are on macOS, press Cmd + Tab instead.

# Updating your keyboard shortcuts using keybindings.json

An alternative approach to updating your keyboard shortcuts for switching tabs is to use your keybindings.json file.

  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. Click on the Open Keyboard Shortcuts (JSON) icon to the left.

open keyboard shortcuts

  1. Add the following objects to your keybindings.json file.
keybindings.json
[ { "key": "ctrl+tab", "command": "workbench.action.nextEditor" }, { "key": "ctrl+shift+tab", "command": "workbench.action.previousEditor" } // ... rest of your keybindings ]

If you are on macOS, use cmd+tab and cmd+shift+tab instead.

Currently, the keyboard shortcuts can also navigate to the next/previous group (if you split your screen).

If you only want to navigate through the tabs of the current group, set the following keyboard shortcuts instead.

keybindings.json
[ { "key": "ctrl+tab", "command": "workbench.action.nextEditorInGroup" }, { "key": "ctrl+shift+tab", "command": "workbench.action.previousEditorInGroup" } // ... rest of your keybindings ]

Now you can use the Ctrl + Tab keys to navigate to the next tab and the Ctrl + Shift + Tab keys to navigate to the previous tab.

# Switching to a specific tab by Index in VS Code

You can also switch to a specific tab by index with:

  • on Windows and Linux - Alt + N, e.g. Alt + 1, Alt + 2.

  • on macOS: Control + N, e.g. Control + 1, Control + 2.

switch between tabs by index

If you'd rather use Ctrl (or Cmd on macOS) + N to switch to a specific tab by index, you have to update your keyboard shortcuts.

  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. Click on the Open Keyboard Shortcuts (JSON) icon to the left.

open keyboard shortcuts

  1. Add the following objects to your keybindings.json file.

Note: Make sure to replace ctrl with cmd if you are on macOS, e.g. cmd+0, cmd+1, etc.

keybindings.json
[ { "key": "ctrl+0", "command": "workbench.action.openLastEditorInGroup" }, { "key": "ctrl+1", "command": "workbench.action.openEditorAtIndex1" }, { "key": "ctrl+2", "command": "workbench.action.openEditorAtIndex2" }, { "key": "ctrl+3", "command": "workbench.action.openEditorAtIndex3" }, { "key": "ctrl+4", "command": "workbench.action.openEditorAtIndex4" }, { "key": "ctrl+5", "command": "workbench.action.openEditorAtIndex5" }, { "key": "ctrl+6", "command": "workbench.action.openEditorAtIndex6" }, { "key": "ctrl+7", "command": "workbench.action.openEditorAtIndex7" }, { "key": "ctrl+8", "command": "workbench.action.openEditorAtIndex8" }, { "key": "ctrl+9", "command": "workbench.action.openEditorAtIndex9" } ]

Once you paste the objects into your keybindings.json file, you can use the ctrl + N (or cmd + N on macOS) keys to switch between tabs by index.

switch between tabs by index with ctrl

# Switch to the previous/next group in VS Code

When you split your screen into 2 or more windows, use the following keyboard shortcuts to switch to the previous or next group.

On Windows and Linux:

  • Ctrl + K Ctrl + Left arrow key to switch to the previous group.
  • Ctrl + K Ctrl + Right arrow key to switch to the next group.

You first press Ctrl+K, release the keys and then press Ctrl + left or right.

On macOS:

  • Cmd + K Cmd + Left arrow key to switch to the previous group.
  • Cmd + K Cmd + Right arrow key to switch to the next group.

switch to previous next group

The default keyboard shortcuts are a bit difficult to remember.

You can update them in your keybindings.json file.

  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. Click on the Open Keyboard Shortcuts (JSON) icon to the left.

open keyboard shortcuts

  1. Add the following objects to your keybindings.json file.

Note: the example uses alt+1, alt+2 and alt+3, make sure to update this depending on your preferences.

For example, on macOS, you can use ctrl+1, ctrl+2 and ctrl+3.

keybindings.json
[ { "key": "alt+1", "command": "workbench.action.focusFirstEditorGroup" }, { "key": "alt+2", "command": "workbench.action.focusSecondEditorGroup" }, { "key": "alt+3", "command": "workbench.action.focusThirdEditorGroup" } // ... your other keyboard shortcuts ]

# Opening the previous editor from history

There is also a command that you can use to open the previous editor from history.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
  1. Type Open Previous Editor from History and select the option.

open previous editor from history

  1. Use the arrow keys to navigate the list and select the file you want to open by hitting Enter.

history of opened files

I've also written an article on how to close the active Tab or all Tabs in VS Code.

# 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.