Andrei Moiseev
Andrei Moiseev

Reputation: 4084

Visual Studio Code: switch-case block content indentation

I enter the following code:

function actionToAppState(action) {
  switch (action) {
    case START:
    doSomething()
  }
}

The doSomething() line should be indented by one more tab. Indeed, I select the function and format it with Ctrl+K+F:

function actionToAppState(action) {
  switch (action) {
    case START:
      doSomething()
  }
}

Why isn't that line indented as I type? How can I fix it?

Upvotes: 0

Views: 3092

Answers (2)

Sujatha Girijala
Sujatha Girijala

Reputation: 1209

You can try this code formatting shortcuts

VSCode on Windows - Shift + Alt + F

VSCode on MacOS - Shift + Option + F

VSCode on Ubuntu - Ctrl + Shift + I

You can also customize this shortcut using preference setting if needed.

Upvotes: 0

Moha Dehghan
Moha Dehghan

Reputation: 18472

Add this to "User Settings":

editor.formatOnType: true

Or more precisely, open File -> Preferences -> Settings, then search for "formatontype", then set editor.formatOnType to true.

Upvotes: 3

Related Questions