Skip to main content

Configure Spacing in VSCode by Language

·2 mins· loading · loading ·
VSCode Tutorial Dev Set Up

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, you can find my articles on other settings below:

VSCode Fonts & Ligatures
·3 mins· loading · loading
Tutorial VSCode Dev Set Up

Create your Own Code Snippets in VSCode
·3 mins· loading · loading
VSCode Tutorial Snippets


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

Kera Cudmore
Author
Kera Cudmore

Comments: