Categories
Mac

Move between Code tabs on Mac

I primarily use macOS but I also use Windows on a regular basis. Or maybe I should say I have to use Windows because of various workplace activities where it makes it easier to do what I have to do. But that is invariably because of corporate IT policies defined by people who, due to malice or just lack of knowledge, go out of their way to make life difficult for non-Windows people.

If I were to point out one thing that irks me it is the inconsistent use of various keyboard shortcuts on Windows. The use of the control key for a lot of things also leads to very awkward finger positions. As a comparison, the command key on Mac is right under the left thumb so it is super easy to achieve various key combinations without moving the hands.

Coming from macOS to Windows I couldn’t wrap my head around how people could actually stand the use of the control key for so many shortcuts and briefly tried to remap the keys to switch ctrl and alt around. But that led to other problems so I abandoned it and, reluctantly, succumbed to the Windows way of doing things – on Windows.

But on macOS I really expect things to work in a consistent manner with all other applications so I was mightily surprised to notice that the default way to switch tabs on Visual Studio Code on macOS uses the control key. Every other program that I know of on macOS that allows the user to jump between tabs uses the command button plus number keys. Even Microsoft’s own Edge browser does it. But not Visual Studio Code! Switching between open documents is something I use frequently so this was a real nuisance. I was frustrated and almost gave up on VS Code.

Luckily VS Code allows for simple keybindings but it is not super intuitive. This is what I did:

  1. In VS Code, open Keyboard Shortcuts (under Code > Settings…)
  2. Open Keyboard Shortcuts (JSON) in the top right, the small document icon with an arrow
  3. Add the mappings below, or use the attached file

This enables Cmd plus numbers to switch between open tabs. Like the standard Cmd+9 switches to the last tab. It is also possible to use Option+Cmd plus arrow keys to move right and left among the tabs.

My sanity is restored. I just don’t understand why this couldn’t be the default mapping for VS Code on macOS to begin with.

[
  {
    "key": "cmd+alt+[ArrowLeft]",
    "command": "workbench.action.previousEditor"
  },
  {
    "key": "cmd+alt+[ArrowRight]",
    "command": "workbench.action.nextEditor"
  },
  {
    "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"
  },
  {
    "key": "cmd+0",
    "command": "workbench.action.lastEditorInGroup"
  }
]
css.php