【问题标题】:How to stop VS Code from auto indenting the expression inside a bracket?如何阻止 VS Code 自动缩进括号内的表达式?
【发布时间】:2020-07-23 21:32:11
【问题描述】:
inl f _ =
    ()

假设我将插入符号放在 () 中,按 Enter + a

inl f _ =
    (
        a
    )

我明白了。我宁愿它不自动缩进,而是执行以下操作。

inl f _ =
    (
    a
    )

language-configuration.json 文件中有以下内容。

{
  "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 对缩进规则有一点要说。

如果没有为编程语言设置缩进规则,编辑器将在行以左括号结束时缩进,在您键入右括号时缩进。这里的括号是用括号定义的。

我猜我正在经历的行为与此有关。如果您查看配置文件,我故意粘贴空规则以避免这种情况,但它不起作用。我应该在这里做什么?

【问题讨论】:

    标签: visual-studio-code


    【解决方案1】:

    我想你可以设置"editor.autoIndent": "none",

    这是来自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",
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-25
      • 2012-04-10
      • 2018-05-03
      • 2021-09-15
      • 2020-11-21
      • 2022-01-13
      • 2023-01-10
      • 1970-01-01
      相关资源
      最近更新 更多