【问题标题】:How to integrate Cmder properly in VS Code?如何在 VS Code 中正确集成 Cmder?
【发布时间】:2019-05-18 21:42:38
【问题描述】:

我想将Cmder shell 集成到我的 VS Code 配置中。

我在 Windows 上使用 VS Code 64bit,我尝试如下修改我的 settings.json 文件,以使 Cmder 作为集成终端工作:

"terminal.integrated.shell.windows": "C:\\Program Files\\Cmder\\Cmder.exe",

我重新启动了我的 VS Code 并尝试打开终端。

一开始出现这个错误提示框:

无法将 ConEmu.xml 文件复制到备份位置!
以管理员身份重启 Cmder。

所以,我以管理员身份启动了 VS Code,这使得错误消息消失了;但是,我注意到 VS Code 在另一个单独的窗口中打开 Cmder,而不是在终端中。

如何在 VS Code 终端中运行 Cmder shell?

附: vs代码文档中的这个注释可以解决吗?

提示: 集成终端 shell 以 VS Code 的权限运行。如果您需要以提升(管理员)或不同权限运行 shell 命令,您可以在终端中使用平台实用程序,例如 runas.exe。"

来自:https://code.visualstudio.com/docs/editor/integrated-terminal

【问题讨论】:

    标签: visual-studio-code cmder


    【解决方案1】:

    你的配置文件有错误,以下是无效有效:

    "terminal.integrated.shell.windows": "C:\\Program Files\\Cmder\\Cmder.exe"
    

    您应该从 VS Code 调用 Cmder.exe,而应该使用 init.bat(根据以下说明)将 Cmder 集成到 VS Code .

    您的问题已通过 Cmder 存储库 here 进行了解释。


    让 Cmder 在 VS Code 中工作

    1. 确保您使用的是最新版本的 Cmder – 下载最新的here

    2. 打开settings.json 配置文件,按Ctrl + , (Control-Comma) 访问首选项,然后点击在 settings.json 中编辑链接

    3. VS Code 文档在此链接中解释了该过程:
      Can I use Cmder's shell with the terminal on Windows?

      是的,要在 VS Code 中使用 Cmder shell,您需要将以下设置添加到您的 settings.json 文件中:

      "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
      "terminal.integrated.shellArgs.windows": ["/K", "C:\\cmder\\vendor\\init.bat"]
      
    4. 顺便说一句,您需要将 C:\\cmder 替换为您自己的安装路径。
      提示: 将单反斜杠 (\) 替换为双反斜杠 (\\)。

    5. 请务必阅读官方 Cmder 的通知wiki:

      ? 请注意使用cmd.exe 而不是cmder.exe

      提示:请参阅 here,了解有关在路径中处理 空格 的说明。
      TL;DR:Cmder 团队不建议这样做, 但您可以在空格前使用^ 字符来处理路径。

    6. 您无需重新启动 VS Code 即可完成这项工作。
      点击 Ctrl + ` (Control-Tilde) 在 VS Code 终端中打开 Cmder!

    您可以参考我的回答 here 以获得有关其工作原理的完整说明。


    相关

    over the VS Code repohere on Cmder repo 也有类似的问题。

    【讨论】:

    • cmd.exe 不是cmder。如果您运行 cmd.exe,您将没有 cmder 提供的 conemu 环境。因此它可能适用于 cmder 的扩展 cmd,但不能正常适用于 git-bash,因为它无法理解在 cmder 中运行时的 ansi 颜色代码。
    • 非常详细的答案!
    【解决方案2】:

    Cmder 1.3.12 引入了一个 vscode_init.cmd 脚本,它允许 VS Code 任务与 Cmder 一起正常工作。

    如果您使用的 Cmder 版本高于 1.3.11,则上述答案中提到的 VS Code 中的文档已过期。

    Cmder GitHub 存储库现在有 extensive documentation 关于如何实现 Cmder 和 VS Code 之间的集成。在撰写此消息时,它比the VS Code documentation 更准确。

    【讨论】:

      【解决方案3】:

      以下对我有用(Cmder 版本大于 1.3.11):

      1. 将 \cmder 目录粘贴到 C:\tools

      2. 粘贴到 .vscode\settings.json 中:

        "terminal.integrated.shell.windows": "cmd.exe",
        "terminal.integrated.env.windows": {
            "CMDER_ROOT": "C:\\tools\\cmder"
        },
        "terminal.integrated.shellArgs.windows": [
            "/k",
            "%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd"
        ],
        

      .. 享受吧!

      【讨论】:

      • 在 vscode 2021 年 4 月更新命令 "terminal.integrated.shell.windows""terminal.integrated.shellArgs.windows" 已弃用。
      • 新命令是什么?我在找那些。
      • @PajriAprilio 关注新问题stackoverflow.com/q/67489288/13499978
      【解决方案4】:

      这在 2021 年 6 月 22 日对我有用;将这些行添加到您的用户设置中的 settings.json 文件中(对我而言 « C:\Users\ianla\AppData\Roaming\Code\User\settings.json »):

      "terminal.integrated.profiles.windows": {
          "cmder": {
            "path": "C:\\WINDOWS\\System32\\cmd.exe",
            "args": ["/K", "C:\\Users\\ianla\\cmder\\vendor\\bin\\vscode_init.cmd"]
          }
        },
        "terminal.integrated.defaultProfile.windows": "cmder",
      

      ...当然,您需要使用您的安装“cmder”安装路径更改我的 « C:\Users\ianla\ »。

      See here for more info

      【讨论】:

        猜你喜欢
        • 2021-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-27
        • 2020-04-29
        • 1970-01-01
        • 1970-01-01
        • 2023-01-15
        相关资源
        最近更新 更多