Keyboard shortcuts for navigating working files in Visual Studio Code

Visual Studio-Code

Visual Studio-Code Problem Overview


I'm a web developer accustomed to Sublime Text. Often I'll have multiple files open and will navigate between them with cmd + option + left (or +right).

I'd love to have something as close to this functionality as possible in Visual Studio Code. From what I've read, in Visual Studio Code it sounds like instead of having multiple documents open in tabs across the top, you're supposed to use the "Working Files" list in the sidebar on the left. A few questions:

  • Is there a keyboard shortcut for navigating between these files sequentially? (the equivalent to cmd + option + left (or +right) in Sublime Text?)
  • Is there a keyboard shortcut for closing a file and removing it from the working files list? cmd + w just closes its editor window.
  • If these shortcuts don't exist by default, can I create them?

I did just discover Ctrl + - and Ctrl + shift + - (ref), which navigate between "edit locations." This is handy, but sometimes it jumps around between different locations in the same file (depending on where you've been editing). Also I would love an option that moved through files sequentially, i.e not based on most recently viewed, but rather top-to-bottom according to how they are listed in the Working Files list.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

I like the idea of having commands for closing a working file or closing all working files and I can look into adding those for the next update.

As for navigation between working files: We have a very powerful tool for navigation called Navigate History. By default it is assigned to Ctrl + Tab and you can leave the Ctrl key pressed and click Tab to cycle through the list of files, similar how you can switch between windows on the OS.

Navigate history is not identical to what you are asking for because it also contains files that you opened that are not in working files. Can you give it a try and report back if it solves the navigation problem for you?

We feel that this is a more natural way of navigating, because you don't have to worry about the order of working files. Instead you navigate across the list of most recently used files.

In our team we are so used to Navigate history that we cannot live without it anymore. Very often we would press Ctrl + Tab one or two times without even looking at the list that opens because we know that the file we want was either one or two history entries away.

Update

With the release of Visual Studio Code 0.5.0 there are now keyboard shortcuts to navigate back and forward in the list of working files. The shortcut is CMD + K + and CMD + K + (on Windows use the Ctrl key).

Solution 2 - Visual Studio-Code

Ctrl + Page Up

Ctrl + Page Down

would be the best answer for navigating sequential tabs.

Solution 3 - Visual Studio-Code

For Macs: from the menu, select menu CodePreferencesKeyboard Shortcuts to open User/keybindings.json. Then inside the square brackets, add:

{ "key": "shift+cmd+[",          "command": "workbench.action.previousEditor"},
{ "key": "shift+cmd+]",          "command": "workbench.action.nextEditor"}

This binds the standard Mac tab switching shortcuts +shift+[ and +shift+] to switch to previous and next tab, respectively. It was tested in Visual Studio Code 1.3.1.

If you'd rather use ++ and ++, the key strings for those are "cmd+alt+left" and "cmd+alt+right". Although from my testing it looks like these are already bound to the appropriate commands by default in Visual Studio Code 1.3.1, so maybe this question is obsolete?

Solution 4 - Visual Studio-Code

I'm used to having the numbered tabs being tabbable with your keyboard. Similar to Google Chrome.

cmd+1 # First tab

cmd+2 # Second tab

etc.

I did not find the settings for this in Visual Studio Code. I was able to map the keys to the arrows to be able to tab through one at a time.

[{    "key": "cmd+shift+left",    "command": "workbench.action.previousEditor"}, {    "key": "cmd+shift+right",    "command": "workbench.action.nextEditor"}]

It is not ideal, but it will do.

Solution 5 - Visual Studio-Code

Default binding for going to desired tab:

Alt + 1

Alt + 2

...

To change, menu FilePreferencesSettingsKeyboard shortcuts → search: openEditorAtIndex

Solution 6 - Visual Studio-Code

I also get annoyed with the default behaviour of cycling through recent files instead of working files, but it turns out you can re-map the keyboard to work a little differently.

To map Ctrl+Tab and Ctrl+Shift+Tab to cycle through working files similar to how other versions of Visual Studio work you can add this to your keybindings file:

[  { "key": "ctrl+tab", "command": "workbench.files.action.openNextWorkingFile" },  { "key": "ctrl+shift+tab", "command": "workbench.files.action.openPreviousWorkingFile" }]

Solution 7 - Visual Studio-Code

Use the out of the box window management hotkeys.

Between Editor Groups

  • Ctrl + 1 to Left
  • Ctrl + 2 to Side
  • Ctrl + 3 to Right
  • Ctrl + K Ctrl + Left to Left
  • Ctrl + K Ctrl + Right to Right

Within an Editor Group

  • Ctrl + Tab to Next

Solution 8 - Visual Studio-Code

New VSCode ver 1.36.1 on my Mac I have to do as following:

    {
        "key": "shift+cmd+[BracketLeft]",
        "command": "workbench.action.previousEditor"
    },
    {
        "key": "shift+cmd+[BracketRight]",
        "command": "workbench.action.nextEditor"
    }

Solution 9 - Visual Studio-Code

Hold ctrl and navigate between files using tab, after selecting the file, release ctrl to go to that file.

Solution 10 - Visual Studio-Code

You can install keybindings like Sublime Text, Atom or any other available on Visual Studio marketplace, look this:

Sublime Text Keymap and Settings Importer

Personally, I like the atom keybindings :)

Atom Keymap

It works like a charm.

Solution 11 - Visual Studio-Code

Ctrl+PageUp: SelectPreviousSuggestion Ctrl+PageDown: SelectNextSuggestion

Solution 12 - Visual Studio-Code

what @Mesco answered still works, but the default bindings have changed to:

Ctrl + 1

Ctrl + 2

To change them from default, you have to:

  1. Preferences > Keyboard Shortcuts
  2. search for: openEditorAtIndex
  3. change keybinding to whatever

Solution 13 - Visual Studio-Code

I still prefer the approach you've described, but it seems the current solution in Visual Studio Code is to use keyboard "chords" as follows:

Previous working file - +K;

Next working file - +K;

Close working file - +K;W

Note: On Windows/Linux, use Ctrl+K instead of +K.

Source

Solution 14 - Visual Studio-Code

In windows you can use Ctrl + Tab

Solution 15 - Visual Studio-Code

For me it was to simply find the certain commands in the keyboard shortcuts and then modify them in a way which I prefer(Mac: CMD+1/2/.../9 respectively).
So navigate to VS Code -> preferences -> Keyboard Shortcuts.
Then search for: workbench.action.openEditorAtIndex1 and remap your desired key to this command.
Do this last step for all nine indices, so you can change between nine open working files. For me this works best because it reminds me of changing between windows tabs on google chrome and etc.

Screenshot of Keyboard Shortcuts

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlaunchoveritView Question on Stackoverflow
Solution 1 - Visual Studio-CodeBenjamin PaseroView Answer on Stackoverflow
Solution 2 - Visual Studio-Codebk jungView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeEliotView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeRickView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeMescoView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeantfxView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeShaun LuttinView Answer on Stackoverflow
Solution 8 - Visual Studio-CodetruongnmView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeRakeshView Answer on Stackoverflow
Solution 10 - Visual Studio-CodeVinicius SouzaView Answer on Stackoverflow
Solution 11 - Visual Studio-CodeVijay KeshriView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeDanielView Answer on Stackoverflow
Solution 13 - Visual Studio-CoderinogoView Answer on Stackoverflow
Solution 14 - Visual Studio-CodeAkshayView Answer on Stackoverflow
Solution 15 - Visual Studio-CodePanagiotis D.View Answer on Stackoverflow