Configure spacing in VSCode by language
I like to use 2 spaces for indenting when writing HTML and 4 spaces for python, but it can be a pain adjusting the tabs or spaces settings in the command palette, as I would usually end up with the wrong spacing convention, which then takes time to refactor.
So I was wondering - is there a way to customise the spaces/tabs used per language? Well I did some research, and it turns out there is! Read on below to learn how to create language specific settings within VSCode.
Hit
ctrl
+Shift
+P
to open command palette and search settingsSelect the option Preferences: Open User Settings (JSON)
This will open a JSON file in your editor. within the json you can include the following code:
"[python]": { "editor.detectIndentation" : false, "editor.insertSpaces": true, "editor.tabSize": 4 },
You can update the language and the number of spaces to be used in the tab size to your personal preferences, so for example if you choose 4, your indents will be 4 spaces long.
⚠️ Have a quick check of your JSON file to make sure there is not already a language identifier already present (for example, this may have already been created if you've specified a formatter for that language). If the language identifier already exists, you can just add your keys and values to the existing record.
To find a list of language identifiers you can check out this document: VSCode Language Identifiers
There are tons of other settings you can configure using the settings.json file other than spacing and formatters, and there are even some amazing articles on Codú that cover some of these:
Share in the comments below if there are any other configurations you use that make coding a breeze! 😊