Visual Studio代码中有快速切换标签的功能吗?

Is there a quick change tabs function in Visual Studio Code?

当前给我一个下拉选项让我选择哪个选项卡的功能实在是太烦人了。是否有可能删除它,以便选项卡可以像在某些现代网络浏览器中一样工作。

Windows

在Windows上使用Visual Studio代码时,可以使用CTRL + PAGE_UP切换到上一个标签,使用CTRL + PAGE_DN切换到下一个标签。

您还可以根据标签的(非零相对)索引切换到标签。您可以这样做,方法是按住 ALT,然后是数字(1 到 9)。

macOS

要在选项卡之间快速导航,请按住 CMD 键,然后按要切换到的选项卡的编号(1 到 9)。

您还可以通过 CMD + ALT + LEFT/RIGHT 键盘快捷键在 previous/next 选项卡之间切换。

请注意,要切换到不同编辑器组中的选项卡,您必须先切换到所需的编辑器组。

专业提示:如果您对任何键绑定不满意,您可以change them使用任何您觉得更舒服的方式!

默认情况下,Ctrl+Tab in Visual Studio 代码按最近使用的顺序循环浏览选项卡。这很令人困惑,因为它取决于隐藏状态。

Web 浏览器按可见顺序循环浏览选项卡。这更直观。

要在 Visual Studio 代码中实现这一点,您必须编辑 keybindings.json。通过 CTRL+SHIFT+P 使用命令面板,输入 "Preferences: Open Keyboard Shortcuts (JSON)",然后按 Enter

然后在文件末尾添加:

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

或者,要仅循环浏览当前 window/split 视图的选项卡,您可以使用:

[
    {
        "key": "ctrl+tab",
        "command": "workbench.action.nextEditorInGroup"
    },
    {
        "key": "ctrl+shift+tab",
        "command": "workbench.action.previousEditorInGroup"
    }
]

或者,您可以使用 Ctrl+PageDown (Windows) 或 Cmd+选项+ (Mac).

macOS - 2017 年修订

在 2017 年,VS CODE 键盘快捷键已更改为 CTRL+1CTRL+2,CTRL+3 等..在选项卡之间切换。

CMD+1, CMD+2, and CMD+3 切换并创建 tab groups

@Combii 我找到了交换的方法

CMD+1, CMD+2, CMD+3CTRL+1, CTRL+2, CTRL+3, ...

在 macOS 中,转到:

Code > Preferences > Keyboard Shortcuts

在该页面上,单击页面右上角的按钮...

并追加下面的配置,然后保存。

[
    {
        "key": "cmd+0",
        "command": "workbench.action.openLastEditorInGroup"
    },
    {
        "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": "ctrl+1",
        "command": "workbench.action.focusFirstEditorGroup"
    },
    {
        "key": "ctrl+2",
        "command": "workbench.action.focusSecondEditorGroup"
    },
    {
        "key": "ctrl+3",
        "command": "workbench.action.focusThirdEditorGroup"
    }
]

您现在可以使用 CMD+[1-9] 在选项卡之间切换,使用 CTRL+[1-3] 来聚焦编辑器组!希望这个回答对你有帮助。

更好的方法是使用 alt+right 和 alt+left 键像 Jetbrains IDE Webstorm 那样导航

这是我的配置。它还包括创建新文件和文件夹

    {
        "key": "ctrl+n",
        "command": "explorer.newFile"
    },
    {
        "key": "ctrl+shift+n",
        "command": "explorer.newFolder"
    },
    { 
        "key": "alt+left",
        "command": "workbench.action.previousEditor" 
    },
    { 
        "key": "alt+right",
        "command": "workbench.action.nextEditor" 
    }

Mac OS

上一个标签:Shift + Cmd + [

下一个标签:Shift + Cmd + ]

Mac OS(备选)

上一个标签:Cmnd + Alt +

下一个标签:Cmnd + Alt +

Windows:

上一个标签:Ctrl + Shift + Tab

下一个标签:Ctrl + Tab

Linux / Windows(备选):

上一个标签:Ctrl + Page Down

下一个标签:Ctrl + Page Up

for linux...我使用 ctrl+pageUp 或 pageDown

如果您使用 VSCodeVim extension, you can use the Vim key shortcuts:

Next tab: gt

Prior tab: gT

Numbered tab: nnngt

When using Visual Studio Code on Linux/Windows, you can use CTRL + PAGE_UP to switch to the previous tab, and CTRL + PAGE_DN to switch to the next tab. You also have the ability to switch to tabs based on their (non-zero relative) index. You can do so, by pressing and holding ALT , followed by a number (1 through 9).

更多详情:check here

这也适用于 MAC OS:

按 select 特定选项卡:Control + 1 或 Control 2,Control3等

按下 show/select 所有可能的标签:Control + Tab.

Visual Studio 代码 v1.35.0 让您设置 (Ctrl+Tab) / ( Shift+Ctrl+Tab) 键序列通过将这些键序列绑定到命令 [=60= 来在编辑器之间顺序切换] 和 "View: Open Previous Editor"。

在 macOS 上:

  1. 导航至:代码 > 首选项 > 键盘快捷键
  2. 搜索或向下导航到以下两个选项:
    • 查看:打开下一个编辑器
    • 查看:打开上一个编辑器
  3. 将两个键绑定更改为所需的键序列。
    • 查看:打开下一个编辑器 -> (Ctrl+Tab)
    • 查看:打开上一个编辑器 -> (Shift+Ctrl+Tab)
  4. 您可能会 运行 陷入绑定冲突。如果是这样,请记下该命令并重新分配或删除现有的键绑定。

如果你搞砸了,你总是可以恢复到给定绑定的默认状态,方法是 right-clicking 在任何键绑定上并选择 "Reset Keybinding"。

使用 Sublime Text 键盘映射。直观多了。

km

导入 Sublime Text 键盘映射:

Name: Sublime Text Keymap and Settings Importer
Id: ms-vscode.sublime-keybindings
Description: Import Sublime Text settings and keybindings into VS Code.
Version: 4.0.3
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.sublime-keybindings

Windows

上一个

Ctrl + Shift + Tab

下一个

Ctrl + Tab

Mac OS

上一个

Shift+ Cmd + [

下一个

Shift + Cmd + ]

@SC_Chupacabra 有修改行为的正确答案。

我通常更喜欢使用 CTRL + PAGE UP / DOWN 进行导航,而不是使用 TAB 键。

    {
        "key": "ctrl+pageUp",
        "command": "workbench.action.nextEditor"
    },
    {
        "key": "ctrl+pageDown",
        "command": "workbench.action.previousEditor"
    }

Linux 匹配浏览器的键映射:

[
    {
        "key": "ctrl+0",
        "command": "workbench.action.lastEditorInGroup"
    },
    {
        "key": "ctrl+1",
        "command": "workbench.action.openEditorAtIndex1"
    },
    {
        "key": "ctrl+2",
        "command": "workbench.action.openEditorAtIndex2"
    },
    {
        "key": "ctrl+3",
        "command": "workbench.action.openEditorAtIndex3"
    },
    {
        "key": "ctrl+4",
        "command": "workbench.action.openEditorAtIndex4"
    },
    {
        "key": "ctrl+5",
        "command": "workbench.action.openEditorAtIndex5"
    },
    {
        "key": "ctrl+6",
        "command": "workbench.action.openEditorAtIndex6"
    },
    {
        "key": "ctrl+7",
        "command": "workbench.action.openEditorAtIndex7"
    },
    {
        "key": "ctrl+8",
        "command": "workbench.action.openEditorAtIndex8"
    },
    {
        "key": "ctrl+9",
        "command": "workbench.action.openEditorAtIndex9"
    },
    {
        "key": "alt+1",
        "command": "workbench.action.focusFirstEditorGroup"
    },
    {
        "key": "alt+2",
        "command": "workbench.action.focusSecondEditorGroup"
    },
    {
        "key": "alt+3",
        "command": "workbench.action.focusThirdEditorGroup"
    }
]

另一种快速更改标签的方法是 VSCode 1.45(2020 年 4 月)

Switch tabs using mouse wheel

When you use the mouse wheel to scroll over editor tabs, you can currently not switch to the tab, only reveal tabs that are out of view.

Now with a new setting workbench.editor.scrollToSwitchTabs this behaviour can be changed if you change it to true.

Note: you can also press and hold the Shift key while scrolling to get the opposite behaviour (i.e. you can switch to tabs even with this setting being turned off).

我找不到 post VS Community,所以我会 post 我的解决方案在这里。


首先,你需要去工具 -> 选项 -> 环境 -> 键盘,然后找到命令 Window.NextTab。在底部附近应该显示 "Use new shortcut in: "。将其设置为全局(应该是默认设置),然后 select 右侧的文本框并点击 Ctrl + Tab。删除 selected 命令的所有当前快捷方式,然后点击分配。对于 Ctrl + Shift + Tab,命令应该是 Window.PreviousTab.

希望这对您有所帮助:) 如果 VS Community 有一个单独的 post,我很乐意将这个 post 移过去。

Linux 当前 Vscode 1.44.1 版本

我们可以对下一个编辑器使用 ctrl+pageupctrl+pagedown 以前的编辑器。

如有需要更改

ctrl+shift+p > Preferences:Open 键盘快捷键。

搜索

nextEditor

如果需要,请单击更改。

我发现 CTRL+TABCTRL+[=13 真的很烦人=]SHIFT+TAB 仅在我将 windows 拆分为多个面板时循环浏览面板中打开的文件(而不是所有面板)。要更改行为,使其循环遍历所有面板,同时在快速打开对话框内保留一次行为,请将这些添加到您的键绑定:

  {
    "key": "ctrl+tab",
    "command": "workbench.action.quickOpenPreviousRecentlyUsedEditor"
  },
  {
    "key": "ctrl+shift+tab",
    "command": "workbench.action.quickOpenLeastRecentlyUsedEditor"
  },
  {
    "key": "ctrl+tab",
    "command": "workbench.action.quickOpenNavigateNextInEditorPicker",
    "when": "inEditorsPicker && inQuickOpen"
  },
  {
    "key": "ctrl+shift+tab",
    "command": "workbench.action.quickOpenNavigatePreviousInEditorPicker",
    "when": "inEditorsPicker && inQuickOpen"
  }

您可以通过多种方式切换选项卡。

  1. 基于位置的现代浏览器方式。
{
       "key": "ctrl+tab",
       "command": "workbench.action.nextEditor"
   },
   {
       "key": "ctrl+shift+tab",
       "command": "workbench.action.previousEditor"
   }
  1. 最近排序
{
   "key": "ctrl+shift+tab",
   "command": "workbench.action.openNextRecentlyUsedEditor"
 },
 {
   "key": "ctrl+tab",
   "command": "workbench.action.openPreviousRecentlyUsedEditor"
 }

我正在为 AutoHotKey 使用此脚本

^+WheelUp::
   WinGetActiveTitle, originalWindow
   WinActivate, ahk_exe Code.exe
   Send ^{PgDn}
   WinActivate, %originalWindow%
return

这让我可以按住 control + shift 并使用我的滚轮在 VSCode 选项卡之间移动,即使是在另一个程序处于焦点状态时也是如此。我对浏览器选项卡和视频控制使用类似的东西。

Vim 用户可能会发现这些键绑定对于在组之间和组内 windows 切换很自然:

    { "key": "ctrl+j", "command": "workbench.action.nextEditorInGroup" },
    { "key": "ctrl+k", "command": "workbench.action.previousEditorInGroup" },
    { "key": "ctrl+h", "command": "workbench.action.focusPreviousGroup" },
    { "key": "ctrl+l", "command": "workbench.action.focusNextGroup" }

如果要在编辑器组之间循环时包含终端,请参见

您只需执行以下操作: 1.) 打开 vscode。 2.) 按 ctrl+k+s(按书写顺序按)。 3.) 在 search bar 中输入以下内容: nextEditorInGroup 按下第一个输入并将其键绑定(按 2 次)到 alt+->(右误)。 4.) 对 nextEditorInGroup 执行相同操作并将其绑定到 alt+<-(left errow)。 5.) 现在您可以通过 alt+left 或 alt+right 绕过选项卡了!