10

I have a .envDEV file name that I use for development environment variables.

And VSCode is not recognizing it as a dotenv file.

enter image description here

If I change the language mode for the file, it seems to work (the proper styles are applied, 'though the icon won't change). But it goes away whenever I close and re-open the file.

enter image description here

I'm trying to set a custom file association for this, but without success so far.

seetings.json

"files.associations": {
  "*.envDEV": "dotenv"      // DOES NOT WORK
  "*.envDEV": ".env"        // DOES NOT WORK
},

Does anybody know how to do this?

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336

3 Answers3

22

By default .env files have a language id of plaintext, but vscode does something special with it to assign a different icon. The only way I've been able to accomplish what you're asking for is with an icons extension.

The dotenv extension adds syntax highlighting and the dotenv language id to all your .env variant files. Pair that with the vscode-icons extensions, and it changes the icon to the gear that the basic .env file has.

With just the icons extension, you can use the properties file association and that works as well, just add the following to settings.json:

"files.associations": {
  ".env*": "properties"
}
Parker
  • 440
  • 3
  • 6
7

With the dotenv extension this works:

"files.associations": {
  "*.env*": "dotenv"      // THIS WORKS NOW
}
Clintm
  • 4,505
  • 3
  • 41
  • 54
6

If you don't want to install a separate extension you can set language mod for .env file as makefile or python to get syntax highlighting and # comment support.

"files.associations": {
    ".env*": "makefile"  // or "python"
  }

enter image description here

Robin Wieruch
  • 14,900
  • 10
  • 82
  • 107
GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
  • 3
    This might technically work for highlighting but `make` is weird... not sure I would recommend doing this. (i.e. $ in a makefile is special) – Clintm Feb 15 '21 at 04:31