DEV Community

Cover image for Configure Spacing in VSCode by Language
Kera Cudmore
Kera Cudmore

Posted on • Updated on • Originally published at codu.co

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.

  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, I've previously written an article covering fonts and ligatures:

Share in the comments below if there are any other configurations you use that make coding a breeze! 😊

Top comments (1)

Collapse
 
nikita_baryshev_698b774fa profile image
Nikita Baryshev

Hey! I was trying to follow different tutorials and finally found this one! The only one that really worked. Thank you!