简体   繁体   中英

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):

{
....
}

I would like the same thing to happen when I use backticks (since I'm using stlyed-components).

So when I input `+enter, I would get:

`
....
`

How do I do that?

You'll need a new keybinding for Enter , with specific conditions. Open Preferences → Key Bindings and add the following to the right side:

    { "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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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