Correct Cursor indentation on the new line after the semicolon in Javascript

Viewed 502

I wish the cursor to be indented properly when I press enter after the semicolon. How can I achieve this in VS Code?

CT

1 Answers

You can turn off wrappingIndent, or set it back to default same, and then ensure formatOnType is set to true:

"[javascript]": {
    "editor.wrappingIndent": "same",
    "editor.formatOnType": true
},

This will put all the new lines the same as the previous, as you type it will automatically indent, where applicable:

cy.visit('/admin/settings/categories/add')
  .get('[data-cy=name]').type('category')

enter image description here

As shown you would have to explicitly press 'Enter'; it doesn't work if you use shortcuts like CTRL + Enter.

One thing none of these wrapper-like settings will take into account is context; say you want to deep indent after the first .get(), arbitrarily for illustration:

cy.visit('/admin/settings/categories/add')
    .get('[data-cy=name]').type('category')
        .checkDb('Category', { name: 'Category 2' })
    .get('[data-cy=submit]').click();

The native formatter will automatically put it back in line with the other children.

This would ultimately need native extension/onEnter support

Related