简体   繁体   English

如何自动添加新行并缩进崇高文本中的反引号?

[英]How do I auto add new lines and indent to a backtick in sublime text?

Using sublime text.使用崇高的文本。 Similar to how when you add a new bracket { and hit enter, it creates a new indented block like so (the.... are spaces):与添加新括号 { 并按 Enter 时的方式类似,它会创建一个新的缩进块,如下所示(... 是空格):

{
....
}

I would like the same thing to happen when I use backticks (since I'm using stlyed-components).当我使用反引号时,我希望同样的事情发生(因为我使用的是 stlyed-components)。

So when I input `+enter, I would get:所以当我输入 `+enter 时,我会得到:

`
....
`

How do I do that?我怎么做?

You'll need a new keybinding for Enter , with specific conditions.您需要具有特定条件的Enter新键绑定。 Open Preferences → Key Bindings and add the following to the right side:打开Preferences → Key Bindings并在右侧添加以下内容:

    { "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 }
        ]
    },

This will only run if you have the "auto_indent" setting on, the selection is empty, and the characters immediately before and after the cursor are backticks.仅当您启用了"auto_indent"设置、选择为空并且紧接在 cursor 之前和之后的字符是反引号时,这才会运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM