0

I'd like to change the 'o' keybinding when in the file explorer of VS Code.

For a directory I'd like to keep the expand/collapse behavior, but for files I'd like the file to open (current behavior) and for the cursor to move to the editor.

starball
  • 20,030
  • 7
  • 43
  • 238
Ty Kroll
  • 1,385
  • 12
  • 27
  • what command is bound to `o`, according to the key bind GUI there is no command bound to `o` – rioV8 May 06 '23 at 15:43
  • "_For a directory I'd like to keep the expand/collapse behavior_" - `o` does not do this. Are you saying you'd like an answer to show _how_ to make `o` do this as well? – starball May 06 '23 at 19:11
  • loosely related: [How can I set focus to the editor after clicking a file in the Explorer View?](/q/75951425/11107541) – starball May 06 '23 at 19:41

1 Answers1

1

You can do this with the following (open keybingings.json with Preferences: Open Keyboard Shortcuts (JSON) in the command palette):

{
    // open file and pass focus to editor
    "key": "o",
    "when": "filesExplorerFocus && !explorerResourceIsFolder",
    "command": "explorer.openAndPassFocus"
},
{
    // toggle folder folding
    "key": "o",
    "when": "filesExplorerFocus && explorerResourceIsFolder",
    "command": "list.select"
}

If you still want to be able to type file names to do quick searches in the Explorer, try adding the following to the when-clauses && !inputFocus && !textInputFocus && !inInteractiveInput && !renameInputVisible.

starball
  • 20,030
  • 7
  • 43
  • 238