Your problem is partly settings related and partly to do with problems with the package itself.
The first thing to note is that the selector
in the auto_complete_triggers
setting is for telling Sublime in what types of files the triggers should be applied. The setting that you outlined above has this set to text.html
, which means that the setting only applies to HTML files.
The top level scope for files of this type is source.ksp
(while editing a file of this type, choose Tools > Developer > Show Scope Name
to see this; the first line in the popup is the one you would use to detect files of a specific type).
So in this case, the setting that you’re adding should look more like:
// Additional situations to trigger auto complete
"auto_complete_triggers": [
{"selector": "source.ksp", "characters": "<$%@!~"}
],
Making this change in your settings will cause the ~
character to open the autocomplete popup as expected. This doesn’t fix the $
issue (more on that in a moment), and it doesn’t provide the completions you want (probably) in response.
If the intent of this is to have ~realvariable
(as in this example) appear in the popup list, that’s not what happens. Instead, it contains a list of every built in function and variable in this language instead. This is partly because of the plugin in this package that’s providing the completions and partly because of a faulty setting provided by the package itself.
On the plugin front, the plugin is explicitly trying to gather all of the completions from the current file that start with the partial word to the left of the cursor, to which it adds the list of built in variables and functions in the language.
Technically this should work (it does for the other types), except that the package provides a broken setting. Specifically, if you use View Package File
from the command palette and enter the filter text ksp ksp settings
, you can find and open KSP (Kontakt Script Processor)/KSP.sublime-settings
.
This is a syntax specific settings file for files of this type that ships directly with the package itself; it’s the packaged version of the syntax specific settings that you created yourself, only these settings are applied first and then your settings are applied on top.
In this file, you can see this setting:
"word_separators": "/\\()\"'-:,;<>~#^&*|+=[]{}`~?",
This setting represents a list of all of the characters that should be considered to separate words (or if you will, they thus aren’t considered a part of a word). The ~
character appears in this setting (twice). That makes Sublime consider the ~
character to be a word separator.
The result of this is that when you type ~|
, the autocomplete popup opens, but there’s no partial word to the left of the cursor. The plugin responds by not trying to get any completions from the buffer (it wants words that start with the partial word, but there is no partial word), and the result is that you only get the default functions and variables.
If you were to modify the setting and apply it in your own settings (along with the one you’re already using from above), the ~
character will open the autocomplete panel and offer all variables that start with ~
:
"word_separators": "/\\()\"'-:,;<>#^&*|+=[]{}`?",
The reason that the $
expansions don’t work is that the plugin isn’t generating them correctly, which is due to the fact that the $
is a special character in the body of a sublime-snippet
, the completions from a sublime-completions
file and the completions returned by a plugin.
Specifically Sublime treats the character specially (as if it starts an internal variable that Sublime should expand when the completion expands), so the completion is technically expanding, but the completion is telling Sublime to replace itself with nothing.
This is a bug in the plugin itself, and has already been reported in the package issue tracker back in 2018. Comments in the issue seem to indicate that you may not need to include the $
in usages of those variables in some cases. On the other hand, the plugin also explcitly tells Sublime to never try to gather its own completions from the file, which means that it’s not possible to autocomplete a variable name at all in that case.
Regardless of that, the fix for this is pretty simple if you want to get this up and running, although it does require modifying a line in the plugin file to get it to fix the completions for you.
In order to do that I would recommend the OverrideAudit package (though I’m biased because I’m the author, it’s more or less made for this kind of thing).
- Install OverrideAudit if it’s not already installed (it’s available in Package Control)
- Open the command palette and choose
OverrideAudit: Create Override
- Select
KSP (Kontakt Script Processor)
, then ksp_plugin.py
- Jump down to line 298, where this line exists:
compl = [(item + "\tdefault", item) for item in compl
- Modify that line to look like this (make sure the indent is not changed; indent is important in Python)
compl = [(item + "\tdefault", item.replace('$', '\\$', 1)) for item in compl
- Save the file
Essentially this is changing the text item
to item.replace('$', '\\$', 1)
, so that in the completion item returned to Sublime, the first $
character (if any) is turned into \$
so that Sublime knows that it should leave it alone.
This change will create a folder named KSP (Kontakt Script Processor)
in your Packages
folder, and inside of that folder a file named ksp_plugin.py
. As long as that file exists (you can find the folder by using Preferences > Browse Packages
) it will be used instead of the version that is provided by the package author. You can remove the change at any time by removing that file.