Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode open workspace folder hotkey

I am wondering if there is a way I could bind a keyboard shortcut to open the OS File Explorer at the root workspace directory.

Furthermore, I would also like to be able to open a specific folder, relative to my workspace path, with the press of a keyboard shortcut.

I have search through the settings file, and for extensions, but I didn't come up with anything yet.

like image 810
Scorb Avatar asked Oct 10 '18 01:10

Scorb


People also ask

What is the shortcut to open folder in VS Code?

Hit Cmd + O on macOS or Ctrl + O on Windows/Linux to activate the open dialog, select a folder, and click "Open." Note: This answer was written before multiple folder workspaces were implemented in VS Code. If you open folders this way, it will replace your entire workspace with the folder you selected to open.

What is Ctrl Shift P in VS Code?

You can define a keyboard shortcut for any task. From the Command Palette (Ctrl+Shift+P), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.action.tasks.runTask command, and define the Task as args .

How do I view workspaces in Visual Studio?

You can look at it by opening it with a text editor. Close the folder you created and close Visual Studio Code. Now find your workspace "file" and double click on it. This will open Visual Studio Code with the folder you created in your workspace.


1 Answers

One way to accomplish this would be by using a task and a keybinding.


Workspace Folder

To open the workspace using shiftctrlalt + t, create a task:

tasks.json

{
    "label": "explore workspace",
    "type": "shell",
    "windows": {
        "command": "explorer ${workspaceFolder}"
    },
    "osx": {
        "command": "open ${workspaceFolder}"
    }
}

Note the task label. Ad a corresponding keybinding:

keybindings.json

{
    "key": "ctrl+shift+alt+t",
    "command": "workbench.action.tasks.runTask",
    "args": "explore workspace"
}

Note the args value matches the task's label value.


Folder relative to workspace

Assume you want to open ${workspaceFolder}/node_modules/.bin. Add the task:

{
    "label": "explore bin",
    "type": "shell",
    "windows": {
        "command": "explorer ${workspaceFolder}\\node_modules\\.bin"
    },
    "osx": {
        "command": "open ${workspaceFolder}/node_modules/.bin"
    }
}

and a corresponding keybinding:

{
    "key": "ctrl+shift+alt+r",
    "command": "workbench.action.tasks.runTask",
    "args": "explore bin"
}

Disclaimer: Only tested on Windows

like image 70
Mike Patrick Avatar answered Oct 11 '22 03:10

Mike Patrick