如何解决当光标在括号中时,如何在按 Enter 时禁用插入新的空行?
重现步骤:
-
简单代码:
if () {}
-
光标在
之间{}
-
我按回车
-
结果:
if () {
}
- 预期结果:
if () {
}
我不想插入一个空行。
可能是默认情况下(添加空行),而当Alt+Enter
时它不添加空行。
我在 vscode 中没有找到设置。我在谷歌上没有找到任何东西。
我试过了:
{
"key": "alt+enter","command": "type","args": {
"text": "\n"
},"when": "editorTextFocus"
}
因为 Alt+Enter
默认什么都不做。
但是,与 onEnterRules
选项一起使用的 editor.autoIndent
函数会检测到 \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","cursorHome"
]
},"when": "editorTextFocus"
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。