Marko Grdinić
Marko Grdinić

Reputation: 4062

How to stop VS Code from auto indenting the expression inside a bracket?

inl f _ =
    ()

Suppose I put the caret inside (), press enter + a.

inl f _ =
    (
        a
    )

I get the above. I'd rather it did not auto indent and instead did the following.

inl f _ =
    (
    a
    )

I have the following in the language-configuration.json file.

{
  "comments": {
    "lineComment": "//",
  },
  "brackets": [["{", "}"], ["[", "]"], ["(", ")"]],
  "autoClosingPairs": [
    { "open": "{", "close": "}" },
    { "open": "[", "close": "]" },
    { "open": "(", "close": ")" },
    { "open": "'", "close": "'", "notIn": ["string", "comment"] },
    { "open": "\"", "close": "\"", "notIn": ["string"] },
  ],
  "autoCloseBefore": "}]) \n",
  "surroundingPairs": [
    ["{", "}"],
    ["[", "]"],
    ["(", ")"],
    ["'", "'"],
    ["\"", "\""],
  ],
  "indentationRules": {
    "increaseIndentPattern": "",
    "decreaseIndentPattern": ""
  }
}

The guide has a bit to say about the indentation rules.

If there is no indentation rule set for the programming language, the editor will indent when the line ends with an open bracket and outdent when you type a closing bracket. The bracket here is defined by brackets.

I am guessing the behavior I am experiencing is related to this. If you look at the config file, I purposely pasted empty rules in an attempt to avoid this, but it did not work. What should I do here?

Upvotes: 1

Views: 1416

Answers (1)

David D'Agostino
David D'Agostino

Reputation: 66

I think you can set "editor.autoIndent": "none",

This is from https://code.visualstudio.com/docs/getstarted/settings

  // Controls whether the editor should automatically adjust the indentation when users type, paste, move or indent lines.
  //  - none: The editor will not insert indentation automatically.
  //  - keep: The editor will keep the current line's indentation.
  //  - brackets: The editor will keep the current line's indentation and honor language defined brackets.
  //  - advanced: The editor will keep the current line's indentation, honor language defined brackets and invoke special onEnterRules defined by languages.
  //  - full: The editor will keep the current line's indentation, honor language defined brackets, invoke special onEnterRules defined by languages, and honor indentationRules defined by languages.
  "editor.autoIndent": "full",

Upvotes: 3

Related Questions