VSCode: keeping indentation on empty lines

Is it possible to force VSCode to keep indentation on empty lines?

I could not find such a setting either in kind or in the "Beautify" extension.

An example of the desired behavior:

enter image description here

UPDATE: in the end, I just switched to Prettier - and I never had to think about the code style again, as it just automatically formats for me.

+17
source share
4 answers

Go to File> Preferences> Preferences. On the right, add the line:

,"editor.trimAutoWhitespace": false

It worked great for me.

+12
source

A bit of an old question, but I found that a combination of settings:

"editor.trimAutoWhitespace": false,
"editor.renderWhitespace": "all"

... worked for me.

+5

, , eslint (/ ) .

"no-trailing-spaces": ["error", { "skipBlankLines": false }],

I have this in my eslintrc.json file and therefore I get errors on empty lines with spaces or tabs on them. Setting "skipBlankLines" to true may work for you.

0
source

The command editor.action.insertLineAftercreates a new line and moves the cursor there, keeping the indent. To attach this command to the Enter key, go to the keyboard shortcuts (press ctrl + k ctrl + s), then click the button with two curly brackets in the upper right corner.

enter image description here

add the following command

    {
    "key": "enter",
    "command": "editor.action.insertLineAfter",
    "when": "editorTextFocus && !editorReadonly"
},

Make sure this is to the end of the Json list.

0
source

Source: https://habr.com/ru/post/1691322/


All Articles