Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 886
Dimitri Williams Avatar asked Apr 13 '19 17:04

Dimitri Williams


People also ask

How do you duplicate in VS Code?

Duplicate line. You can make the duplications of the same line using: Mac — Command + Shift + D. Windows/Ubuntu — Ctrl + Shift + D.

How do I open the current directory in VS Code?

Great, now to open a folder to VSCode, just type code . and it'll magically open your folder into a new VSCode window! . being the current folder, if you'd like to open another folder, replace .


3 Answers

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+h",
  "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.

like image 108
VonC Avatar answered Oct 17 '22 01:10

VonC


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.

like image 44
Mark Avatar answered Oct 17 '22 03:10

Mark


By default, the terminal will open at the folder that is opened in the Explorer. The hotkey for that depends on your operating system, in my case, on macOS, it's + `, on Windows I think it's ctrl + j.

If you want to open at a specific folder you can change that behaviour with this setting:

{
    "terminal.integrated.cwd": "/home/user"
}

If you want to open at the current file's directory you can install an extension like Terminal Here.

You can change the shortcuts/hotkeys for many actions on Code. For that open the Keyboard Shortcuts editor under File > Preferences > Keyboard Shortcuts and search for Toggle Integrated Terminal.

enter image description here

like image 7
Diogo Rocha Avatar answered Oct 17 '22 03:10

Diogo Rocha