Sublime Forum

Type a pair of braces and move the right brace over a block of text down below?

#1

I would like to know how to move a brace or whatever across/over some text in one go and without any selection.

Here’s the gif showing ST and what I’m talking about:

I would only guess that it’s some plugin/package adds this functionality. Correct?

Thank you very much!

0 Likes

#2

ST provides a default wrap_block command which does something like that based on indentation levels.

The default binding for it is

	{ "keys": ["{"], "command": "wrap_block", "args": {"begin": "{", "end": "}"}, "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 },
		]
	},

Not sure what sets indented_block though.

1 Like

#4

Whether { invokes wrap_block depends on the conditions specified in context array.

0 Likes

#6

The indented_block context comes from the Default/block.py (and the wrap_block command also comes from the same plugin)

0 Likes

#7

Thanks everybody for the explanation. And thank you very much, deathaxe, for introducing me this powerful context feature (which I had no idea was a thing in ST).

In order for the command wrap_block with its default binding settings to work, apart from the indentation, the line on which you type { must have no spaces.

What’s still a mystery to me though is how they (I’m talking about the gif example) typed the brace pair first on one line and then moved the right brace down.
In my case when I type a left brace the closing one is immediately placed under the indented part below.

0 Likes