Sublime Forum

Using tab to escape auto-completed quotes

#1

The automatic-quote/bracket completion in Sublime Text is very useful, but I’ve found myself often wanting to use tab to jump to the right of an auto-completed quote.

Tab is easily accessible, and the alternative (moving my right hand to hit the right arrow) just feels a little cumbersome and, at least for me personally, feels like it really slows me down. Sure it’s only a few milliseconds, but it just feels cumbersome.

Would anyone know how to set up a custom keybinding that when tab is pressed moves the cursor one character to the right, if and only if there is a quote or bracket to the right of it?

Alternatively are there any ways people rely on (other than VIM - I’m not that hardcore yet) to move the cursor over the auto-completed brackets/quotes?

0 Likes

Trouble altering user defined key bindings
#2

Check out the default key bindings, e.g.:

[code] { “keys”: “]”], “command”: “move”, “args”: {“by”: “characters”, “forward”: true}, “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 }
	]
},

[/code]

0 Likes

#3

[quote=“adzenith”]Check out the default key bindings, e.g.:

[code] { “keys”: “]”], “command”: “move”, “args”: {“by”: “characters”, “forward”: true}, “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 }
	]
},

[/code][/quote]

Cheers! That worked a charm.

For anyone else that might want it, here is the modified code

{ "keys": "tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "auto_complete_visible", "operator": "not_equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^(\\]|\\)|\\}|>|\\\"|'|\\;)", "match_all": true }
      ]
   }

It makes it so pressing tab moves the cursor forward one step if it is before any of the following characters (not including commas): ], ), }, >, ", ', ;

Edit: I’ve modified the code to allow for auto-completion. There are probably other cases where this breaks, but I’ll try to fix them if I find any.

0 Likes

#4

Small improvement: also add this condition:

{ "key": "has_next_field", "operator": "not_equal", "operand": true }

This way, if you have snippets that uses any of those operands, will keep working.

0 Likes