Search code examples
visual-studio-code

How to Get Auto-Complete Suggestions Like in VS Code's keybindings.json


I'm trying to get auto-complete suggestions in my file.json like the ones in my VS Code keybindings.json file.

In other words, I want to get this list: example image (key, command, when, etc...) but in my file.json

I tried using the $schema key in my file1.json but I couldn't find the right value for it:

{
  "$schema": "..."
}

Solution

  • Solution

    You need to use your settings.json file to specify the schema you are looking for.

    We will use the json.schemas key, it's an array of objects. Each object can have the following properties:

    • fileMatch: An array of file patterns to match against.
    • url: The URL of the schema.
    • schema: Custom schema to use.

    So you need to add the following to your settings.json:

    {
      "json.schemas": [
        {
          "fileMatch": ["file.json"],
          "url": "vscode://schemas/keybindings"
        }
      ]
    }
    

    Now, when you open your file.json, it will validate against the keybindings.json schema.

    Notes

    This applies the keybindings.json schema to any file named file.json anywhere in your machine.

    To limit it to a specific file, use an absolute path and lowercase the drive letter. For example:

    "fileMatch": ["c:/absolute/path/to/file.json"]
    

    To limit it to your workspace, use .vscode/settings.json instead of the global settings.json. The .vscode folder must be at the root of your workspace for this to work.