【问题标题】:Variables in VS Code settings, how?VS Code设置中的变量,如何?
【发布时间】:2019-11-13 23:16:33
【问题描述】:

在 VS Code 设置中,我配置了一些相同的字段。这些将是字体和字体大小。一般来说,我将它们都设置为相同。我正在尝试在 settings.json 中设置一个变量,该变量可以应用于所有这些变量。在阅读了 VS Code 的 Variables Reference 之后,我想到了以下内容:

{
  "common": [
    {
      "font": "Anonymous Pro",
      "fontSize": 10,
    }
  ],

  // Set up the Editor
  "editor.fontFamily":              "${common:font}",
  "editor.fontSize":                "${common:fontSize}",
  "terminal.integrated.fontFamily": "${common:font}",
  "terminal.integrated.fontSize":   "${common:fontSize}",
  "debug.console.fontFamily":       "${common:font}",
  "debug.console.fontSize":         "${common:fontSize}",
}

不过,这似乎不起作用。有没有办法在 settings.json 中设置变量而无需设置环境变量?

谢谢!

【问题讨论】:

    标签: visual-studio-code vscode-settings


    【解决方案1】:

    目前您无法在settings.json 文件中设置变量。

    目前 VS Code 实现此功能的未解决问题在这里:https://github.com/microsoft/vscode/issues/2809

    它还没有 PR,问题的开端发生在 2016 年 2 月,但最近 2 个月内有 cmets。

    【讨论】:

      【解决方案2】:

      这是不可能的。您提供的链接指出:

      launch.json 和 tasks.json 中的键和值字符串支持变量替换 ...

      所以不支持settings.json

      【讨论】:

        【解决方案3】:

        你想达到什么目的?您可以在 VSCode 中设置项目特定的设置。您可以根据项目使用不同的字体和设置。但我不认为settings.json 支持变量。

        【讨论】:

          【解决方案4】:

          VScode: Defining own variables in tasks.json

          查看这个可能会有所帮助

          【讨论】:

          • 现在变量在setting.json 中被接受到
          • 我不相信您引用的 PR 涵盖了我最初要求的内容。如果我正确地跟随面包屑,它会导致这个request 目前没有关闭。
          • 对不起,我误解了这个问题,但我认为他们无法解决这个问题,但你可以尝试一个 hack,试试这个 [链接] (stackoverflow.com/questions/48595446/…) 它在 launch.json 中设置环境变量
          • 请检查我的新答案
          猜你喜欢
          • 2020-04-28
          • 1970-01-01
          • 1970-01-01
          • 2019-06-30
          • 1970-01-01
          • 2019-03-08
          • 2018-10-19
          • 1970-01-01
          相关资源
          最近更新 更多