visual-studio-code - 当光标在括号中时按 Enter 时,如何禁用插入新的空行?
问题描述
重现步骤:
简单的代码:
if () {}
光标在
{}
我按 Enter
结果:
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
来按照我想要的方式工作。
解决方案
您可以使用扩展多命令并构建一个执行您想要的命令。
将此添加到您的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"
}
推荐阅读
- python - 使用 Pandas 从多个 Excel 文件中读取和合并数据
- json - 如何在flutter的模型类中存储复杂的json数据
- c# - 在尝试调用之前检查协程是否存在
- html - Bootstrap-Select 下拉菜单未打开
- vba - Powerpoint Chart: Axis 类的 xlValue 和 xlCategory 查询
- ios - SwiftUI - 当单击弹出窗口中的按钮时,关闭弹出窗口并将按钮添加到当前主视图
- vuejs2 - Vuetify 同时设置工具栏和导航抽屉
- react-native - 警告 VirtualizedList:您的列表很大,更新 Purecomponent 很慢
- javascript - 如何通过单击 html 图像来启动模式窗口/弹出 .js 文件中的对象数据?
- firebase - GCP - Cloud Firestore API 调用如何收费?