简体   繁体   中英

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:

  • 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, ie not based on most recently viewed, but rather top-to-bottom according to how they are listed in the Working Files list.

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

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?

Ctrl + Page Up

Ctrl + Page Down

would be the best answer for navigating sequential tabs.

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.

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

Default binding for going to desired tab:

Alt + 1

Alt + 2

...

To change, menu FilePreferencesSettingsKeyboard shortcuts → search: openEditorAtIndex

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

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

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.

Ctrl+PageUp : SelectPreviousSuggestion Ctrl+PageDown : SelectNextSuggestion

按住ctrl并使用tab在文件之间导航,选择文件后,松开ctrl以转到该文件。

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

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

在 Windows 中,您可以使用 Ctrl + Tab

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.

键盘快捷键的屏幕截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM