Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Sublime Text 3 from wrapping lines in curly braces

I'm working with a Handlebars (.hbs) file that looks something like this:

<div>
  ...

  _
  <button {{action "signin"}}>Sign in</button>
</div>

When I place the cursor at the underscore position and enter a curly brace {. It wraps the entire <button> line in braces:

{
<button {{action "signin"}}>Sign in</button>
}

But what I want is just:

{}
<button ...

[ and ( don't have this behavior. Is there any way to disable this feature of Sublime Text? I took a look through the keybindings but couldn't find the differences between square brackets and curly braces that make them act differently.

like image 919
Dihedral Avatar asked Jun 06 '26 07:06

Dihedral


1 Answers

My solution relies on you having a syntax applied, so may or may not work out of the box.

Try adding the following into your user key bindings.

{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{${0:$SELECTION}}"}, "context":
    [
        { "key": "indented_block", "match_all": true },
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "source.handlebar", "match_all": true },
    ]
}

I guessed a scope for handlebar, so change it if you need to. If you do not have a syntax definition associated with the file type, comment and I'll update my answer.

For future reference, I found the command being run by doing "sublime.log_commands(True)" in the console. From there I found the related key binding and created a way to override for a specific type of file.

like image 85
skuroda Avatar answered Jun 07 '26 22:06

skuroda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!