Question

How to change the terminal to the current directory in visual studio code ? (hotkey)

In class we had a hotkey for using the terminal with the currently choosen directory. I fixed an issue now with the debugger and everything seems to run smoothly now. Yet, what hotkey fixes this issue?

 46  145141  46
1 Jan 1970

Solution

 50

With VSCode 1.39 (Sept. 2019), no more plugin needed.
You now can "Open new terminals with custom working directories"

There is a new command that allows the creation of terminals with a custom current working directory (cwd):

{
  "key": "cmd+shift+c",
  "command": "workbench.action.terminal.newWithCwd",
  "args": {
    "cwd": "${fileDirname}"
  }
}

You can create your own keyboard shortcuts to open new terminals in any number of handy working directories.
The cwd value can either be a normal path or a variable.


ChrisoLosoph mentions in the comments:

What to do with the pasted code snippet:

  • press F1,
  • Enter, and
  • select "Open Keyboard Shortcuts (JSON)"
  • and paste it there.
2019-10-09

Solution

 27

For a hotkey to quickly set your terminal folder to your current directory, see How to quickly change shell folder to match the currently open file

{
  "key": "alt+t",
  "command": "workbench.action.terminal.sendSequence",
  "args": {"text": "cd '${fileDirname}'\u000D"}
},

This will change your current terminal, not open a new terminal - if you want to do that see the link above as well for the new command recently added to vscode.

Note that on windows, you must use the following instead:

"args": {"text": "cd /d \"${fileDirname}\"\u000D"}

This is because on Windows, the /d parameter must be used with cd to switch drives.

2019-10-10