4

In VS Code settings, there are some fields which I configure the same. These would be namely font and font size. Generally I have them all set to the same. I am trying to set up a variable in the settings.json which can be applied to all of them. After reading through Variables Reference for VS Code, I came up with the following:

{
  "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}",
}

Though, this doesn't seem to work. Is there a way to setup variables within the settings.json without having to setup environment variables?

Thanks!

lordhog
  • 3,001
  • 5
  • 28
  • 38

4 Answers4

1

Currently you cannot set variables in the settings.json file.

The current open issue for VS Code to implement this feature is here: https://github.com/microsoft/vscode/issues/2809

It has yet to have a PR and the opening of the issue occurred Feb 2016, but with comments within the last 2 months.

lbow
  • 11
  • 2
0

This is not possible. The link you provided states:

Variable substitution is supported inside key and value strings in launch.json and tasks.json ...

So there is no support for settings.json.

John Archer
  • 2,062
  • 2
  • 23
  • 32
0

What are you trying to achieve? You can set project specific settings in VSCode. So much you can have a different set of fonts and settings based on the project. But I don't think the settings.json supports variables.

Yathi
  • 909
  • 1
  • 10
  • 21
0

VScode: Defining own variables in tasks.json

Check out this Might help I have developed a python script that reads any *.json file and replace content with $[] with its actual value

  • now variables are accepted in `setting.json` to – Lakshmikanth Ayyadevara Nov 13 '21 at 09:45
  • I don't believe the PR you referenced covers what I was originally asking for. If I followed the crumbs correctly it lead to this [request](https://github.com/microsoft/vscode/issues/2809) which isn't closed at the moment. – lordhog Nov 16 '21 at 22:36
  • sorry I misunderstood the question but I think their is no way around for this problem, but you can try one hack , try this [link] (https://stackoverflow.com/questions/48595446/is-there-any-way-to-set-environment-variables-in-visual-studio-code) it sets env variables inside `launch.json` – Lakshmikanth Ayyadevara Nov 17 '21 at 11:50
  • Please check my new answer – Lakshmikanth Ayyadevara Nov 30 '21 at 06:38