DEV Community

Gregor Martynus
Gregor Martynus

Posted on

VS Code ProTip™: paste path of active file into terminal

I need to use the path to the current active file in my VS Code editor all. The. Time!

Eventually I figured there must be a shortcut but there is none that's built-in. However, you can quickly add it yourself.

  1. Open the command palette (Windows: Ctrl+Shift+P, Mac: Command+Shift+P)
  2. Search for "Preferences: Open Keyboard Shortcuts (JSON)"
  3. In the opened keybindings.json file, add a new item to the array
  {
    "key": "ctrl+shift+t",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "${relativeFile}" },
    "when": "terminalFocus"
  }
Enter fullscreen mode Exit fullscreen mode

Now open any file, then open a terminal within VS Code, and press Ctrl+Shift+T and it will paste the full path to that file where your cursor is in the terminal.

Top comments (0)