Sublime Forum

Typing over ";"

#1

Hi all,

in ST, i can type “)”, “”", “}” and some others and if it’s already the next character to come, ST will simply jump over it instead of adding a new one.
Working a lot in as3 / js / css, I’d like to have that functionality for the “;” as well since I always type it in and it just doubles the one that was generated by the snippets.
Is there any setting i can use to get that behaviour? I’m using ST2 right now, but am perfectly willing to switch if that’s available in ST3.

bw,
Tobl

0 Likes

#2

Add this into your keymap file:

[code]{ “keys”: “;”], “command”: “move”, “args”: {“by”: “characters”, “forward”: true}, “context”:

  { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
  { "key": "following_text", "operator": "regex_contains", "operand": ";", "match_all": true }
]

} [/code]

0 Likes

#3

thanks a lot iamntz, works like a charm.

0 Likes

#4

This is a feature of having “auto_match_enabled”; for consistency’s sake you might want to limit it by that by adding the following to your context:

{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },

You might also want to throw an additional line to limit it to appropriate syntaxes. Add this to your context (adjusting the scopes as desired):

{ "key": "selector", "operator": "equal", "operand": "source.css, source.less, source.scss", "match_all": true },

Just some thoughts I’ve had while tinkering with similar keybindings in Markdown. It’s actually quite easy to overdo it and trip yourself up. (The asterisk in Markdown is particularly interesting :smile: )

Alex

0 Likes

#5

Thanks again iamntz and alex.

It works really nicely, but from time to time i get unexpected behaviour and I just figured out what it is.

      { "key": "following_text", "operator": "regex_contains", "operand": ";", "match_all": true }

checks the entire following text, so a selection like this ( | is the selection-marker )
MyT|ext;
returns true. Is there a way to check only the very next character?

bw,
Tobl

0 Likes

#6

Okay, found the answer to the last question by myself. “^” in regex will specify the start of string. The complete and (hopefully) correct keybinding now looks like this:

	{ "keys": ";"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
		
			{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
			{ "key": "selector", "operator": "equal", "operand": "source.css, source.less, source.scss, source.actionscript.2, source.js", "match_all": true },
			{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
			{ "key": "following_text", "operator": "regex_contains", "operand": "^;", "match_all": true }
		]
	},
0 Likes

#7

Good catch @Tobl. I encountered the issue also, but I forgot to post the fix here. The binding in your last post is very close to what I’m using as well.

Alex

0 Likes