VSCode - Shortcut to open terminal to the directory of currently opened file

By xngo on June 18, 2021

  1. Open File > Preferences > Keyboard Shortcuts.
    VSCode - File > Preferences > Keyboard Shortcuts
  2. Right-click and select Add Keybinding....
    VSCode - Add Keybinding
  3. Type in your desired shortcut keys.(e.g. Alt+t)
  4. For my case, I chose Alt+t, which already existed.
  5. I doubled click on 1 existing command has this keybinding to open it.
    VSCode - existing command has this keybinding
  6. Click on the Open Keyboard Shortcuts (JSON) button to open the JSON configuration settings.
    VSCode - Open Keyboard Shortcuts (JSON) button
  7. Change JSON to the following code.
{
    "key": "alt+t",
    "command": "workbench.action.terminal.newWithCwd",
    "args": {
        "cwd": "${fileDirname}"
    }
}

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.