Hi All,
What’s meaning of the $0 $1, $2 symbols in the snippets?
Thanks!
$1 is the initial caret position when you first time press the Tab key.
$2 is the position after you press the Tab key again.
$3 is … again and again.
$4 is … again, again and again.
$0 is the ending position.
Yes; they can be triggered by plugins, you can bind them to a key, and any snippet that applies to the current situation (based on the scope
) will automatically appear in the command palette with the Snippet:
prefix on its name.
Could you provide an example please? E.g. how to set the CTRL+SPACE as a snippet trigger
As for the scope, I know there is a “file type / extension” scope… Are there another scopes, which could be defined in snippets?
You can use Preferences > Key Bindings
and search the left hand pane for insert_snippet
; various key bindings that ship by default do it.
The ones that take contents
as an argument specify the content of the snippet directly. You will also see an example that uses name
and specifies Packages/XML/Snippets/xml-long-tag.sublime-snippet
as the snippet to expand.
If your snippet content is small and simple and you only want to insert it based on a key press, contents
is the fastest way; if you also want to be able to use the snippet generically in other places, then you need to create the sublime-snippet
file and use the second version of the command to invoke it.
Snippets don’t define scopes; only syntax definitions do that. Various places in Sublime use the scopes defined by syntax definitions to know what to do, such as color schemes using it to know when to change colors.
Snippets themselves can use any scope; for example you could set it to source.python
to make it available anywhere at all inside of a Python source file, or you could set it to source.python comment
to make it only available inside of a comment in a Python source file, etc.
When I start typing a snippet key, a window pops up with some garbage:
Why? What’s wrong?
Or I just tying something and some window with very strange content pops up:
What’s wrong? How to fix this behavioral ?
That’s not related to your original question but it looks like it’s pulling completions from words in the buffer and you’re editing files that contain a lot of long character data sequences.
How can I empty this “buffer”? How can I filter out the files, which may enter their contents into this before and which ones no… In fact, the Project contains a lot of garbage files…
When I press a TAB key for the snippet triggering, a first characters string is selected… How to change this behavioral ? How to place snippets being first in this pop up window/buffer?
How can I change the Auto-Completion Key being different from the TAB key (it doesn’t make sense mapping both Auto-Completion and Snippet triggers to the same keys…)
You can use this setting to have some control over the ordering of the items in the list:
// Controls how the auto complete results are reordered when typing:
// - "none" will fully reorder the results according to how well the
// completion matches the typed text.
// - "some" will partially reorder the results, taking into account how
// well the completion matches whats typed, and likelihood of the
// completion.
// - "strict" will never reorder the results.
"auto_complete_preserve_order": "some",
Not sure what you mean about the second item; the tab
key (or enter
if you change settings) selects the current item while the auto completion panel is open, regardless of what item is selected or what it’s type is. You can alter the key that does it, but not just for snippets; the new key would still just expand out anything selected just like tab
does.