Sublime Forum

Changing the Bracket Indentation

#1

I’d like to change the default style that sublime uses. I like the auto-indentation, but currently the style is driving me nuts.

The format I like is this:

function stuff () { my stuff }

However, when I type the opening bracket, it’s not auto-indented, resulting in this:

function stuff () { }

I’ve either got to manually space over before typing the bracket (which kind of defeats the point of having auto-indentation) or I’ve got to fix the brackets myself after they appear. Then, when I hit enter to begin adding lines, this happens:

function stuff () { | }

Also not what I want. I tried looking through the settings under preferences, but I mostly found options for how far to indent or to turn indentation off, etc:

"tab_size": 2, "translate_tabs_to_spaces": false, "use_tab_stops": true, "detect_indentation": true, "auto_indent": true,

How do I get sublime to indent the brackets and stop indenting the code inside the brackets?

0 Likes

#2

This is a quite complex change with how indentation is currently set up.

You’ll need to adjust regular expressions for indentation detection/prediction via docs.sublimetext.info/en/latest/ … f-settings and you need to change override the following default key binding:

[code] { “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 }
	]
},[/code]
0 Likes