9

In chrome and most other browsers/editors, we can go to a particular tab by pressing the Command key and the number. For example: If we press Command+1 we will go to the first tab, Command+2 takes to the second tab, etc.

Is it possible to get such a key mapping for Visual studio code ?

Sankar
  • 6,192
  • 12
  • 65
  • 89

6 Answers6

12

Since VSCode uses ctrl+number by default (which changes desktops in macOS), you can use cmd+number with custom keybindings:

Paste this in your keybindings.user:

  {
    "key": "cmd+1",
    "command": "workbench.action.openEditorAtIndex1"
  },
  {
    "key": "cmd+2",
    "command": "workbench.action.openEditorAtIndex2"
  },
  {
    "key": "cmd+3",
    "command": "workbench.action.openEditorAtIndex3"
  },
  {
    "key": "cmd+4",
    "command": "workbench.action.openEditorAtIndex4"
  },
  {
    "key": "cmd+5",
    "command": "workbench.action.openEditorAtIndex5"
  },
  {
    "key": "cmd+6",
    "command": "workbench.action.openEditorAtIndex6"
  },
  {
    "key": "cmd+7",
    "command": "workbench.action.openEditorAtIndex7"
  },
  {
    "key": "cmd+8",
    "command": "workbench.action.openEditorAtIndex8"
  },
  {
    "key": "cmd+9",
    "command": "workbench.action.openEditorAtIndex9"
  },
joepio
  • 4,266
  • 2
  • 17
  • 19
  • 1
    You can also change the cmd+9 to map to the last element to match other mac apps [this worked for me](https://stackoverflow.com/questions/39245966/vs-code-possible-to-switch-tabs-files-with-cmdnumbers#comment91039925_41112036) – Dave Oct 08 '19 at 22:39
  • To precise what Dave says, search `workbench.action.lastEditorInGroup` (or just `last editor`) to set the shortcut – lolesque Feb 06 '23 at 14:41
5

This is available now, with the latest version of Visual Studio Code. See: https://github.com/Microsoft/vscode/issues/24753#issuecomment-294518439

Sankar
  • 6,192
  • 12
  • 65
  • 89
  • 1
    On macOS, the shortcuts default to `ctrl` + *n*, not `cmd` + *n*. You can fix that in Code -> Preferences -> Keyboard Shortcuts. Another note: most other apps activate the last tab with `cmd`+`9`. I'm not sure whether VSCode can do that easily. – tuomassalo Feb 11 '18 at 08:26
  • adding to the above instructions: to find the command in the keyboard shortcuts, search for `index` in the keyboard shortcuts and edit e.g. `workbench.actiton.openEditorAtIndex1` – Dan Tanner Apr 23 '18 at 18:54
  • 1
    @tuomassalo can you post your text as an answer? – SuperUberDuper Jul 21 '18 at 13:38
3

On macOS, the shortcuts default to ctrl + n, not cmd + n. You can fix that in Code -> Preferences -> Keyboard Shortcuts.

Another note: most other apps activate the last tab with cmd + 9. You get that behavior by using workbench.action.lastEditorInGroup instead of workbench.action.openEditorAtIndex9.

tuomassalo
  • 8,717
  • 6
  • 48
  • 50
  • I recommend sticking with `ctrl`+`n` in case you want to run VS code within your browser as in github.dev – huyz Nov 02 '22 at 08:52
1

This comes standard with the "Emacs Keymap" extension as well as a multitude of other "never touch the mouse" keybindings that I, personally, find keep my stress level way down while navigating code.

Now all I need to find is a way to put the tab's number on the tab itself (which is what I was searching when I found this question).

0

Unfortunately, no. But you can configure shortcuts to move between tabs, such as going to the previous, next, previously modified, etc. tabs. You can make changes in the Options menu under Keyboard.

chris g
  • 1,088
  • 10
  • 18
0

For MacOS users:

control + 1: Will go the first tab opened.

control + 2: Will go the second tab opened.

...

control + 0: Will do the last tab opened.

ahmnouira
  • 1,607
  • 13
  • 8