Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode doesn't syntax highlight all .env files [duplicate]

VSCode being strange about environment files. Even though it shows the correct file icon for the example.env as a dotenv file in the file view/tab, only .env is syntax-highlighted correctly when opening the file.

.env (correct):

enter image description here

example.env (no syntax highlighting):

enter image description here

What's the best way to get all .env files syntax highlighted properly in VSCode?

like image 782
shennan Avatar asked Jul 11 '26 03:07

shennan


1 Answers

VS Code has a way to manually define the file association of certain extension types.

To do so for .env files:

  1. Open Settings (Ctrl + , or File > Preferences > Settings.
  2. Search for file asssociation.
  3. You should see Files: Associations.
  4. In the table under this setting, click on Add Item.
  5. Under Item, add *.env and under Value, add properties.
  6. Click on OK once you're done.

You can also do the same for .env.example files.

Switching back to your file, you should see the syntax highlighted.

like image 63
M69k65y Avatar answered Jul 13 '26 17:07

M69k65y