Search code examples
visual-studio-codevscode-keybinding

How can I navigate and manipulate list views in VS Code using the keyboard?


I want to use the keyboard only to navigate inside and manipulate list views in VS Code, such as

  • the Explorer View's subviews, like Open Editors, Folders, Outline, and Timeline
  • the Source Control View's subviews, like Source Control (and the nested parts of that, like staged changes and unstaged changes), and Source Control Repositories
  • the Run and Debug View's subviews like Variables, Watch, Call Stack, and Breakpoints
  • the Extensions View's subviews

How can I do this?


Solution

  • The keyboard shortcuts you're interested in are listed in the keyboard shortcuts UI with IDs all starting with "list.".

    In short, to move focus, you can use the arrow keys- Up and down arrow keys go up and down, and left and right arrow keys can be used to expand and collapse nested things. Left inside something nested can be used to jump to the parent of the nest, and enter can be used to select the focused item, and space on the parent of a nest can be used to toggle expand/collapse of it. Hold ctrl and use arrow keys to scroll, and hold shift and use arrow keys to extend or contract the selection. And other goodies (read on).

    The full definition of default keybindings on Windows and Linux is as follows (you can find this in the defaultKeybindings.json pseudo file by using the Preferences: Open Default Keyboard Shortcuts (JSON) in the command palette- they're probably largely the same on macOS- just using cmd instead of ctrl):

    For controlling focus

    { "key": "up",       "command": "list.focusUp",       "when": "listFocus && !inputFocus" },
    { "key": "down",     "command": "list.focusDown",     "when": "listFocus && !inputFocus" },
    { "key": "home",     "command": "list.focusFirst",    "when": "listFocus && !inputFocus" },
    { "key": "end",      "command": "list.focusLast",     "when": "listFocus && !inputFocus" },
    { "key": "pageup",   "command": "list.focusPageUp",   "when": "listFocus && !inputFocus" },
    { "key": "pagedown", "command": "list.focusPageDown", "when": "listFocus && !inputFocus" },
    

    For scrolling

    { "key": "ctrl+down", "command": "list.scrollDown", "when": "listFocus && !inputFocus && listScrollAtBoundary != 'both' && listScrollAtBoundary != 'bottom'" },
    { "key": "ctrl+up",   "command": "list.scrollUp",   "when": "listFocus && !inputFocus && listScrollAtBoundary != 'both' && listScrollAtBoundary != 'top'" },
    

    For expand and collapse

    { "key": "space",     "command": "list.toggleExpand", "when": "listFocus && !inputFocus" },
    { "key": "right",     "command": "list.expand",       "when": "listFocus && treeElementCanExpand && !inputFocus || listFocus && treeElementHasChild && !inputFocus" },
    { "key": "left",      "command": "list.collapse",     "when": "listFocus && treeElementCanCollapse && !inputFocus || listFocus && treeElementHasParent && !inputFocus" },
    { "key": "ctrl+left", "command": "list.collapseAll",  "when": "listFocus && !inputFocus" },
    

    For invocation

    { "key": "enter", "command": "list.select", "when": "listFocus && !inputFocus" },
    

    For selection

    { "key": "ctrl+shift+enter", "command": "list.toggleSelection",     "when": "listFocus && !inputFocus" },
    { "key": "shift+down",       "command": "list.expandSelectionDown", "when": "listFocus && listSupportsMultiselect && !inputFocus" },
    { "key": "shift+up",         "command": "list.expandSelectionUp",   "when": "listFocus && listSupportsMultiselect && !inputFocus" },
    { "key": "ctrl+a",           "command": "list.selectAll",           "when": "listFocus && listSupportsMultiselect && !inputFocus" },
    { "key": "escape",           "command": "list.clear",               "when": "listFocus && listHasSelectionOrFocus && !inputFocus" },
    

    For find

    { "key": "f3",     "command": "list.find",      "when": "listFocus && listSupportsFind" },
    { "key": "ctrl+f", "command": "list.find",      "when": "listFocus && listSupportsFind" },
    { "key": "escape", "command": "list.closeFind", "when": "listFocus && treeFindOpen" },
    

    You can customize these to your heart's content.

    Note that not all lists have the same capabilities, so you might observe some differences in what these keybindings do in context. For example, in lists that have no concept of selecting things (in the sense of multiple selection of items), the selection keybindings may do nothing or just move focus, and in lists that have no concept of selecting something (in the sense of selecting a single thing to perform some associated action of its), the selection keybinding might just do something like toggle expansion.