Sublime Forum

Disable skipping over closing parenthesis/brackets?

#1

One small thing that’s annoyed me for a long time is that if you have the caret to the left of a closing parenthesis/brackets/quote etc. and try to insert another of that same symbol, it just moves one step to the right instead. Is there any way to disable this, while still keeping the automatic insertion of closing parenthesis/bracket/quotes?

0 Likes

#2

Why not just type } or ) or ] two times? The first time the cursor moves over the existing one, the second time the insertion takes place.

You can find the logic for this in the default keybindings, it’s quite elaborate. Just open the keybindings and look for the binding with key ")" for example.

You could create a new keybinding for e.g. "ctrl+)" that ignores all that logic and just inserts a closing brace, no matter what the context is.

1 Like

#3

Yeah of course, But after three years of using Sublime Text it’s still annoying.

Thank you! :smile:

Fixed it by setting these key bindings:

{ "keys": ["]"], "command": "insert_snippet", "args": {"contents": "]"}, "context":
	[
		{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true },
		{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "\\[$", "match_all": true }
	]
},
{ "keys": ["}"], "command": "insert_snippet", "args": {"contents": "}"}, "context":
	[
		{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true },
		{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "\\{$", "match_all": true }
	]
},
{ "keys": [")"], "command": "insert_snippet", "args": {"contents": ")"}, "context":
	[
		{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
		{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "\\($", "match_all": true }
	]
},
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\""}, "context":
	[
		{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^\"", "match_all": true },
		{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
		{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double - punctuation.definition.string.end", "match_all": true },
	]
},
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'"}, "context":
	[
		{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^'", "match_all": true },
		{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
		{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "match_all": true },
	]
}
1 Like