Configure spacing in VSCode by language

Configure Spacing in VSCode by Language Image

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.

  1. Hit ctrl + Shift + P to open command palette and search settings

  2. Select the option Preferences: Open User Settings (JSON)

  3. 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! 😊

How ToDev Set UpVscode
Avatar for Kera Cudmore

Written by Kera Cudmore

Junior Software Developer at the Met Office | Code Institute Alumna.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.