launchoverit
launchoverit

Reputation: 5227

Keyboard shortcuts for navigating working files in Visual Studio Code

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:

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.

Upvotes: 78

Views: 112942

Answers (15)

Mesco
Mesco

Reputation: 1393

Linux default bindings for going to desired tab within current editor group is:

Alt + 1
Alt + 2
...

To change, menu FilePreferencesKeyboard shortcuts → search: openEditorAtIndex


Linux default bindings for switching between editor groups is:

Ctrl + 1
Ctrl + 2
...

To change, menu FilePreferencesKeyboard shortcuts → search: focusFirstEditorGroup, focusSecondEditorGroup ect.

Upvotes: 9

Rakesh
Rakesh

Reputation: 167

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

Upvotes: 5

Panagiotis D.
Panagiotis D.

Reputation: 81

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

Upvotes: 0

Akshay
Akshay

Reputation: 41

In windows you can use Ctrl + Tab

Upvotes: 0

truongnm
truongnm

Reputation: 2474

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"
    }

Upvotes: 4

Daniel
Daniel

Reputation: 365

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

Upvotes: 3

Vinicius Souza
Vinicius Souza

Reputation: 445

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.

Upvotes: 0

Rick
Rick

Reputation: 13510

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.

Upvotes: 10

Eliot
Eliot

Reputation: 5659

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?

Upvotes: 43

rinogo
rinogo

Reputation: 9163

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

Upvotes: 0

mikedavies-dev
mikedavies-dev

Reputation: 3355

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" }
]

Upvotes: 7

Benjamin Pasero
Benjamin Pasero

Reputation: 124314

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

Upvotes: 111

Vijay Keshri
Vijay Keshri

Reputation: 507

Ctrl+PageUp: SelectPreviousSuggestion Ctrl+PageDown: SelectNextSuggestion

Upvotes: 1

bk jung
bk jung

Reputation: 471

Ctrl + Page Up

Ctrl + Page Down

would be the best answer for navigating sequential tabs.

Upvotes: 44

Shaun Luttin
Shaun Luttin

Reputation: 141712

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

Upvotes: 6

Related Questions