Sublime Forum

Idea for known parameters

#1

Within snippets I wanted to be able to cycle through acceptable parameter values. For example, in CSS I want to be able to cycle through the list-style-types none, circle, disc, square (among others). The problem is, if we enable completions within snippets (fields) then we might be able to press TAB to cycle through the choices, but then how do we move to the next field? I thought I would post the following idea in case it is of use or interest to anyone :smile:

Firstly, create a new user, key-binding:

[code]
{ “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “\t”, “exact”: true} },
{ “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “\t”, “exact”: false},
“context”:

		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+right"], "command": "replace_completion_with_next_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+left"], "command": "replace_completion_with_prev_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
}

][/code]
I’m using Ctrl-Alt-Left or -Right. (I took a stab in the dark that “replace_completion_with_prev_completion” exists :wink: )

Create a CSS completions file:

[code]{
“scope”: “source.css”,

"completions":  
 	{ "trigger": "shape", "contents": "none" },
 	{ "trigger": "shape", "contents": "circle" },
 	{ "trigger": "shape", "contents": "disc" },
 	{ "trigger": "shape", "contents": "square" }
]

}[/code]
Then either modify the relevant snippet, or create a new one, that uses the term ‘shape’ as a parameter.

When using the snippet you can either overtype the parameter (shape) or press the right-arrow to move the cursor after the word, and use Ctrl-Alt-Right or Left to cycle through the options. Once you’ve made your choice you can then press TAB to continue to the next field.

Note that the word ‘shape’ will really only be of use within a snippet. Outside of a snippet pressing Ctrl-Alt-Right will cycle through other completions - that is, it won’t stick to the shape list :cry:

I hope this might be of interest to someone, or perhaps someone might suggest an improvement to it? Regards, Andy.

0 Likes