Sublime Forum

Quote completion, cursor advance?


I like the feature of quote completion, it’s very helpful. But, when I’m done typing within that area, is there some quick way I can advance the cursor to the end without having to manually do this with the -> arrow key or by typing an end quote (redundant).

For example:

list = [‘sometext’ <-- I want to get here, to the END of the line, after the auto-completed ’ quote, but if I continue to have to manually move, it ends up annoying.



Apart from pressing End to jump to the end of the line (for your particular example above) I think you would need to modify the key bindings that are providing the auto-pairing to do something like this (or perhaps there is a package that provides similarly functionality so you don’t have to do it yourself).

For example the binding for auto-pairing a single quote is the following (taken from the default key bindings):

	{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'$0'"}, "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": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
			{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "['a-zA-Z0-9_]$", "match_all": true },
			{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "match_all": true }

The contents argument of the insert_snippet command is what is injecting the pair of quotes in response to a single press, with $0 representing the position the cursor ends up at.

If you copy the binding into your user keybindings you can modify the snippet to something like:

"command": "insert_snippet", "args": {"contents": "'$1'$0"}

In this case when the snippet expands the cursor will end up at $1 for you to enter the contents of the quotes, and pressing Tab will jump the cursor to $0 for you.

The downside of this is that it’s easy to get into a position where the snippet is still active even though you don’t realize it; for example pressing Backspace to delete both quotes or pressing to close the quote.

In such a case the status line will say you’re on Field 1 of 2 and the next time you press Tabthe cursor will jump to where the closing quote was, which is a bit disconcerting.

You could get around that to a large degree by also modifying some of the other bindings so that in addition to removing the quotes or skipping over the ' character they also use the clear_fields command to exit the snippet, though.



Additionally, if you just type a ’ with your caret right in front of a’, st will move over it instead of inserting another one.



Thank you everyone for your replies :slight_smile: