如何在 Visual Studio Code 中使用面包屑栏快速打开具有特定路径的终端?

huangapple go评论60阅读模式
英文:

How can I open a terminal with a specific path quickly using the vscode breadcrumbs bar?

问题

我想使用VS Code的面包屑栏(位于文件名栏正下方的栏)快速打开一个具有特定路径的终端,就像“右键单击”,“Ctrl-单击”或其他键绑定快捷方式一样。这是否可能?是否有其他快速打开具有特定路径的终端的方法?

我在VS Code代码导航中搜索了设置,但没有得到我想要的。

英文:

I want to use the VS Code breadcrumbs bar(the bar just below the file name bar) to open a terminal with specific path quickly, like right-click, ctrl-click or other keybinding shortcuts. Is it possible? Is there other way to open a terminal with specific path quickly?

I searched the settings in VS Code code navigation, but didn't get what I want.

答案1

得分: 1

{
  "key": "alt+c",
  "command": "runCommands",
  "args": {
    "commands": [
      "workbench.action.terminal.new",
      {
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "cd '${fileDirname}'\u000D"
        }
      }
    ]
  }
}

\u000D 是一个回车符,所以 cd 命令会立即执行。

英文:

If you just want to open a new terminal while changing to the active file's directory, then use this keybinding (in your keybindings.json):

{
  "key": "alt+c",              // whatever keybinding you want
  "command": "runCommands",
  "args": {
    "commands": [

      "workbench.action.terminal.new",    // open a new terminal
      {
        // send the cd current file directory command to the new terminal
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "cd '${fileDirname}'\u000D"
        }
      }
    ]
  }
}

\u000D is a return so the cd command runs immediately.

答案2

得分: 0

关于 @starball 建议的问题,存在一个默认(可能的)键绑定快捷方式 cmd K + P(MacOS)来复制活动文件的路径。

{
  "key": "cmd+k p",
  "command": "workbench.action.files.copyPathOfActiveFile"
}
英文:

Relating to @starball 's suggestion, there exists a default(maybe) keybinding shortcut cmd K + P(MacOS) to copy the path of the active file.

{
  "key": "cmd+k p",
  "command": "workbench.action.files.copyPathOfActiveFile"
}

答案3

得分: 0

我不知道通过面包屑的方式可以实现,但至少有两种解决方法:

  • 在资源管理器视图中右键单击文件夹/目录,然后单击“在集成终端中打开”。如果您将explorer.autoReveal设置保持在默认值true,可能会更容易找到此选项。对于这种解决方法,您可能还会对此功能请求感兴趣:https://github.com/microsoft/vscode/issues/67711。

  • 使用命令面板中的“文件:复制活动文件的路径”命令(或绑定到的键绑定,我认为默认是ctrl/cmd+p)。然后将其粘贴到您的 shell 中的cd命令中。

英文:

I'm not aware of a way with breadcrumbs, but there are at least two workarounds:

  • Right click the folder/directory in the Explorer View and then click "Open in Integrated Terminal". This may be easier to find if you have the explorer.autoReveal setting left at its default value of true. For this workaround, you might also be interested in this feature-request: https://github.com/microsoft/vscode/issues/67711.

  • Use the File: Copy Path of Active File command in the command palette (or whatever keybinding it is bound to. I think the default is <kbd>ctrl/cmd</kbd>+<kbd>p</kbd>). Then paste that into a cd command in your shell.

huangapple
  • 本文由 发表于 2023年5月30日 12:30:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76361639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定