Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set file association to custom .env filename in VSCode settings?

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?

like image 414
cbdeveloper Avatar asked Feb 19 '20 11:02

cbdeveloper


People also ask

How do I set file associations in Visual Studio Code?

Open your settings (CMD + , on a Mac or CTRL + , on Windows) and enter a file association. We can do this with the settings UI or the settings JSON, both are options to edit your settings. Then enter a file association for the .

How do I create an env file in VS Code?

Once you have opened the folder, click on the Explorer icon on the top left corner of the VSCode (or press Ctrl+Shift+E) to open the explorer panel. In the explorer panel, click on the New File button as shown in the following screenshot: Then simply type in the new file name . env ...

How do I add custom settings to VS Code?

Settings editor# To open the Settings editor, use the following VS Code menu command: On Windows/Linux - File > Preferences > Settings. On macOS - Code > Preferences > Settings.


2 Answers

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"
}
like image 136
Parker Avatar answered Oct 16 '22 08:10

Parker


With the dotenv extension this works:

"files.associations": {
  "*.env*": "dotenv"      // THIS WORKS NOW
}
like image 7
Clintm Avatar answered Oct 16 '22 07:10

Clintm