Search code examples
text-filesvscode-extensions

How can I create a VSCode snippets extension for text files?


Here is my package.json file:

{
  "name": "trsnippets",
  "displayName": "testRigor Snippets",
  "description": "Snippets for the most common commands on the testRigor tool.",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.76.0"
  },
  "categories": [
    "Snippets"
  ],
  "contributes": {
    "snippets": [
      {
        "language": "txt",
        "path": "./snippets/snippets.code-snippets"
      }
    ]
  }
}

I chose txt as the language when creating the folders with yeoman, but it doesn't consider text files.


Solution

  • You need to use the language identifier for text files: plaintext, not txt. The language identifier is not the file extension.

    If you hover over the "language" key it tells you that. And then to find the languageID or language identifier for text files: open a .txt file and look in the lower right-hand corner of the editor and you'll see Plain Text - but you would use plaintext as the language identifier.

    Which you can see if you click on that Plain Text text (it is a button) and look for plain text in the dropdown window. The languageID is that part in parentheses at the end of each filetype line like (plaintext).