skip to Main Content

I want to customize my vscode for the keyboard only experience (sort-of).
Right now, if I open my file explorer and select via the arrow keys the needed file and press enter – it opens that file, focuses the editor (explorer gets unfocused) – but it does not close the file explorer.

So I need to press my combination to focus the explorer back, and then press that again – to close the explorer and focus back the editor.

My question is – how to close the explorer when I open a selected file?

I tried to find the command that is responsible for opening a new file, or an event, but did not find any solution…

2

Answers


  1. You can achieve this functionality by editing your configuration by following these steps:

    1. Open your Keyboard Shortcuts
    2. Click on the {} icon at the top right to open keybindings.json.
    3. Add the following code:
    {
        "key": "enter",
        "command": "workbench.action.quickOpenNavigateNextInFilePicker",
        "when": "explorerViewletFocus && !inputFocus"
    },
    {
        "key": "enter",
        "command": "workbench.action.closeSidebar",
        "when": "explorerViewletFocus && !inputFocus"
    }
    

    Then save the file and try it.
    Explanation:
    This setup allows you to close the Explorer when you press Enter after selecting a file. The quickOpenNavigateNextInFilePicker command ensures that the file opens, and closeSidebar will close the Explorer.

    Login or Signup to reply.
  2. You can use the runCommands command to run multiple commands.

    In this case, there are two commands you want to happen when you press enter:

    • open the selected file, list.select
    • close the sidebar, workbench.action.closeSidebar.

    To run both commands on enter, use the following keyboard shortcut:

        {
            "key": "enter",
            "command": "runCommands",
            "when": "explorerViewletFocus && filesExplorerFocus && !inputFocus",
            "args": {
                "commands": [
                    "list.select",
                    "workbench.action.closeSidebar"
                ]
            }
        },
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search