Issue #38 (Default Language and File Associations)01/11/23
|
Get a weekly dose of tools, articles, and other resources covering remote work, productivity, career well-being, and lots more.
|
|
|
VS Code allows you to make a few
language and file-specific changes to suit your needs, depending on the kinds of languages you work with.
First of all, opening a new file in VS Code defaults the file's "language" to "plain text". You can see the current language (or syntax) in the bottom right area of the status bar in your editor.
You can click it to change the language of the current file, but it's more than likely that you don't want this to default to plain text. To
change the default language for a new file, search for "defaultLanguage" in your settings.
This brings up the "Files: Default Language" setting, which you can change by typing in the name of the language you want as the default. The name, with some exceptions, should be typed in all lowercase and is generally the same as the name itself (e.g. "Python" is "python", "JavaScript" is "javascript", etc). The VS Code docs have a
full reference here.
With this in place, all new files will automatically use syntax highlighting for the default language you select, and saving the file will default to that language's file extension.
You can also look for the setting "files.Associations", which allows you to
associate languages with file extensions. This might be useful if you're using noncustomary file extensions for different files. The VS Code docs include an example using .php4 and .php5 file extensions.
This way you can instruct VS Code what to do with those files since it won't naturally associate those file extensions with PHP. You can change this in the UI settings and it will look as shown in the screenshot above in your JSON settings.