Problem with Indentation

Asked

Viewed 12,523 times

2

I recently switched from editor to developer.

With VS Code everything has become easier and more intuitive, but I often have problems with old classes, regarding indentation.

When I open the first time all the code seems to be well organized, but during the use I see that some parts were not indented correctly. A "strange space" appears, as if it were 4 spaces in one, it makes the indentation does not work perfectly, then I need to go out manually adjusting.

This is boring because there are hundreds of "classes" with thousands of command lines.

I have already looked and the automatic indentation of VS Code stored.

2 answers

0


I think this occurs because VS Code has a default indentation setting, but its old files have another.

You can use the default VS code formatting option. Here’s a 15-second video explaining. https://www.youtube.com/watch?v=OhnlywA-Jrs

Or you can use some Beautify extension, install and read the documentation. With this extension you can easily identify the entire file or part of it. https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify

Another option is to change setting the use of Tab in the VS Code settings. Go on File > Preferences > Settings and search for "Tab", as per image

inserir a descrição da imagem aqui

You can also give a Ctrl+A to select all lines in the file. Then go to Ctrl + shift + p > indent as in the image below and choose the format you want.

inserir a descrição da imagem aqui

0

To set indentation spaces for both new and old files, for 2 in this case ("editor.tabSize": 2) you must insert the following code in the configuration file:

"[typescript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features",
        "editor.tabSize": 2,
        "editor.insertSpaces": true,
        "editor.detectIndentation":false
 }

To access the settings press CTRL + SHIT + P and type in the command line:

Preferences: Open Settings (JSON)

or to directly configure a language type in the command line:

Preferences: Configure Language Specific Settings

and choose the language you want to configure

You can add specific settings for each manual link by entering in the JSON configuration Settings.json:

"[javascript]": {
    "editor.tabSize": 2,
    "editor.insertSpaces": true,
    "editor.detectIndentation":false
} 

"editor.detectIndentation":false causes the indentation of old files to be ignored

Browser other questions tagged

You are not signed in. Login or sign up in order to post.