Sublime Forum

Why does auto_indent replace 'tab' with 'reindent' on empty lines?

#1

The ‘auto_indent’ setting has the following keybinding associated with it:

{ "keys": ["tab"], "command": "reindent", "context":
	[
		{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
		{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
	]
},

I’ve triggered this many, many times, and it’s always been an unpleasant surprise. I asked elsewhere how to disable the associated behavior, but leave the rest of auto_indent intact, and eventually managed to figure it out myself. When I asked, the main reaction I got was concern that doing so would “break smart indenting”, and cause trouble with use cases that I never quite understood from the comments.

So, now that I know how to enable and disable this rule, what’s it for? Why is reindent preferable to indenting up to the first tab stop? Keep in mind that if I add newlines from the end of the last line of the preceding block, the cursor will be properly indented, and any new lines that I leave blank will auto-delete their added indents.

0 Likes