首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按Enter键后未获得额外行Sublime Text 3

按Enter键后未获得额外行Sublime Text 3
EN

Stack Overflow用户
提问于 2021-06-09 02:41:38
回答 1查看 67关注 0票数 0

我有一个初始的开始场景,其中|表示我的光标:

代码语言:javascript
复制
for(int i=0;i<n;i++){|}

按回车键后的结果:

代码语言:javascript
复制
for(int i=0;i<n;i++){
|}

期望的结果:

代码语言:javascript
复制
for(int i=0;i<n;i++){
    |
}

我尝试了this,但它没有解决我的问题。

我使用了下面的键绑定,但它不起作用:

代码语言:javascript
复制
[
   { "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
        [
            { "key": "setting.auto_indent", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "{$", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^}", "match_all": true }
        ]
    }
]

另外,我的这些键绑定设置如下:

代码语言:javascript
复制
"auto_indent": true, 
"smart_indent": true, 
"indent_to_bracket": true,
"trim_automatic_white_space": true,

我怎么才能修复它?

编辑:-我卸载了Sublime Text4并安装了Sublime Text3。它工作得很好。我会坚持下去的。

EN

回答 1

Stack Overflow用户

发布于 2021-06-10 22:09:09

完整的键绑定应该是:

代码语言:javascript
复制
[
   { "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
        [
            { "key": "setting.auto_indent", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
        ]
    }
]

如果您希望方括号[ ]出现相同的行为,则需要以相同的方式对它们进行转义,因为它们在正则表达式中也是特殊字符。

编辑

下面是直接从Sublime Text 3复制的快捷键,在ST4中也是一样的:

代码语言:javascript
复制
[
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
    ]
},
]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67892845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档