Issue #37 (Language Specific Settings)01/04/23
|
Get a weekly dose of tools, articles, and other resources covering remote work, productivity, career well-being, and lots more.
|
|
|
A really powerful way to customize your settings in VS Code is by means of language-specific settings. This feature allows you to
use different settings depending on the programming language (or file type) you're coding in.
For example, you might want to use 4 spaces for indenting your PHP, Python, or another back-end language; but when you're working in JavaScript or CSS, you might prefer 2 spaces. You might also have some different preferences for something like Markdown or HTML, since they're quite different from those other languages.
Let's use PHP and CSS to demonstrate. In the Settings UI, you'll notice there's a little filter button in the top-right area of the editor, next to the search box. If you click this button, you'll see a "Language..." option.
If you choose that option, the search field will be populated with "@lang:", followed by some language options to choose from in a dropdown. If you select PHP, you'll be presented with what looks like a regular list of settings. But these will be applied only when you're coding in PHP.
As a side point here, technically you don't have to use the "filter" option, you can simply type
@lang: into the search box, followed by the language in which you want to namespace your settings.
Once the language namespace is defined in the search box, you can scroll down to start changing settings for that language, or type a keyword to look for a specific setting. Once you've changed a few settings for a particular language,
you can see all your new language-specific settings in your settings JSON file.
Notice in my example, I have two settings for CSS and two for PHP. What you see in that screenshot is
the JSON syntax for any language specific settings, assuming you want to edit directly in the JSON this way, rather than using the Settings UI.
If you want to go directly to the JSON file with the language ready to be used, you can open your command palette and type "Preferences: Configure Language Specific Settings". From there, you'll get a dropdown list of language options. When you choose a language, you'll be taken immediately to your default settings editor (UI or JSON, depending on what you have as your
workbench.settings.editor value). Usefully, the JSON editor provides all the possible options via a dropdown, if you want to go the JSON route.