Goland Formatting Setting for Case Statement


Hello, when I format my code, the opening brace for the case statement ends up on the next line. Like:

case 25: 


      // do something


I want it like:

case 25: {

  // do something.


I tried the 'Wrapping and Braces' section in the Go Code Style settings. But I dont see enough controls there.

Official comment


It's default gofmt formatting behavior and there is no way to change it (please see: https://go.dev/play/p/S9zn8tGJ-oR, press Format button and case 1: will be reformatted with braces on newlines).

Also, please see: https://github.com/golang/go/issues/3859

Hy there i can see your post and i must say

  1. Open GoLand Settings:

    • On Windows/Linux: Go to "File" > "Settings."
    • On macOS: Go to "GoLand" > "Preferences."
  2. Navigate to Code Style:

    • In the left sidebar, click on "Editor" and then select "Code Style."
  3. Choose Go Language:

    • In the "Code Style" section, select "Go" from the drop-down menu.
  4. Open the Formatting Options:

    • Under the "Code Generation" tab, you'll find options for formatting various code constructs, including "Case statements."
  5. Adjust Case Statements Formatting:

    • Look for the "Case statements" section.
    • Here, you can customize how case statements are formatted. You might find options for indentation, braces placement, and more.

Thanks and regards



Thanks Ryan for the reply. Interestingly, I don't see the 'Code Generation' tab under Go for Code Style. Attached is the screenshot.


Please sign in to leave a comment.