首页 > 解决方案 > 带有目录的VSCode打开终端似乎不起作用

问题描述

找到VSCode 命令 workbench.action.terminal.newWithCwd

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

我无法让它工作。

我已经将上面的 JSON 插入到~\Code\User\keybindings.json文件中,但我如何真正让它执行呢?

标签: visual-studio-codeterminalkeyboard-shortcuts

解决方案


这可以用作键绑定,使用宏扩展multi-command

{
  "key": "alt+k",       // whatever you want here
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      {
        "command": "workbench.action.terminal.newWithProfile",
        "args": {
          "profileName": "Git Bash",
          "shouldForwardArgs": true,
        }
      }
      {
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "cd '${fileDirname}'\u000D"
        }
      }
    ]
  },
  "when": "editorTextFocus"
},

我认为应该起作用的是settings.json中的这个配置文件:

    "terminal.integrated.profiles.windows": {
      "PowerShell": {
        "source": "PowerShell",
        "icon": "terminal-powershell"
      },
      "Command Prompt": {
        "path": [
          "${env:windir}\\Sysnative\\cmd.exe",
          "${env:windir}\\System32\\cmd.exe"
        ],
        "args": [],
        "icon": "terminal-cmd"
      },
      "Git Bash": {
        "source": "Git Bash",
        "path": "C:\\Program Files\\Git\\git-bash.exe"
      },
      "Git Bash at fileDirname": {
        "source": "Git Bash",
        "path": "C:/Program Files/Git/git-bash.exe",
        "args": [
          "cd ${fileDirname}"       // variables are supported here according to the docs
        ]
      }
    },

然后是这个关联的键绑定:

  {
    "key": "alt+k",
    "command": "workbench.action.terminal.newWithProfile",
    "args": {
      "profileName": "Git Bash at fileDirname",
      "shouldForwardArgs": true
    }
  },

但这对我来说不太奏效。它几乎可以工作,但它说不存在这样的文件。我在配置文件中看到了一些关于可变分辨率的问题。


推荐阅读