当光标在括号中时按 Enter 时如何禁止插入新的空行?

How do I disable inserting a new empty line when I press Enter when the cursor is in brackets?

重现步骤:

if () {
  
}
if () {
}

我要空行不要插入

可能是默认情况下(加空行),Alt+Enter时不加空行

我没有在 vscode 中找到设置。我在 google.

上没有找到任何内容

我试过这个:

{
  "key": "alt+enter",
  "command": "type",
  "args": { 
    "text": "\n" 
  },
  "when": "editorTextFocus"
}

因为 Alt+Enter 默认情况下什么都不做。 但是,与 editor.autoIndent 选项一起使用的 onEnterRules 函数会检测到 \n 字符的添加,并且无论如何都会添加一个额外的空行。 :(

我想用editor.autoIndent。但是我想使用快捷方式 Alt+Enter.

关闭(不要打开)

最糟糕的选择:寻找功能与 editor.autoIndent 完全相同但能够创建快捷方式 Alt+Enter 以按我想要的方式工作的扩展程序。

您可以使用扩展 multi-command 并构建一个命令来执行您想要的操作。

将此添加到您的 settings.json(全局或工作区)

  "multiCommand.commands": {
    "multiCommand.lineBreakNoEmptyline": {
      "sequence": [
        "lineBreakInsert",
        "deleteWordRight",
        "cursorRight",
        "cursorHome"
      ]
    }
  }

将此添加到您的 keybindings.json:

  {
    "key": "alt+enter",
    "command": "multiCommand.lineBreakNoEmptyline",
    "when": "editorTextFocus"
  }

或者使用仅键绑定方法

  {
    "key": "alt+enter",
    "command": "extension.multiCommand.execute",
    "args": { 
      "sequence": [
        "lineBreakInsert",
        "deleteWordRight",
        "cursorRight",
        "cursorHome"
      ]
    },
    "when": "editorTextFocus"
  }