Sublime Forum

[Solved] How to use/add custom autocompletion?

#1

Hello,

I’m trying to modify the existing html autocompletions. To do so, I have tried:

  1. Modifying the existing “HTML.sublime-complesions” in “AppData\Roaming\Sublime Text 2\Packages\HTML”:
    changing
{ "trigger": "a", "contents": "<a href=\"$1\">$2</a>" },

to

{ "trigger": "a", "contents": "<abc href=\"$1\">$2</abc>" },
  1. adding a custom “HTML.sublime-completions” in “AppData\Roaming\Sublime Text 2\Packages\User”:
    consisting of

[code]{
“scope”: “text.html - source - meta.tag, punctuation.definition.tag.begin”,
“completions”:

	{ "trigger": "a", "contents": "<abc href=\"$1\">$0</abc>" }
]

}[/code]

  1. Doing both at once.

However, none of them adds any new option to the completions-list or changes the result of the autocomplete, even though modifying the preferences or snippets works perfectly fine.
Is there an obvious reasons / something I’m doing wrong that prevents this from working? If so, how should I implement custom completions to override the default ones?

Thanks in advance,
Tobl

My system:
Windows 7 64-bit;
Sublime Text 2, Version 2.0.1, Build 2217

0 Likes

#2

Okay, after a lot of research, I’ve got it working.
If anyone encounters the same problem, here’s what I did, however, I think it’s very likely that I’ll soon encounter problems with this solution/workaround:

The problem with modifying the HTML.sublime-completions is that they’re overwritten by the html_completions.py . Aside from learning Python there’s two ways around this:

A: make your modifications to the HTML.sublime-completions and delete/rename the html_completions.py . The problem with this approach is, that every update will overwrite your custom file and replace the python. You therefore would have to make a backup of your file and change the files after every update.

B: copy the HTML.sublime-completions into your User -Package, add your modifications and rename it into something that’s not in use already. Fancy stuff like MyPersonalHTML.sublime-completions will work. Now open the preferences.sublime-settings in the User Package and add the line

"ignored_packages": "Vintage", "HTML"]

The problem with this approach is, that the entire HTML-Package will be ignored. So if there are other important things in that folder, they’ll be missing if you don’t copy them as well. I’m pretty new to sublime, so I can’t tell you if any of the files will have an impact.

Finally, there’s one problem both approaches share. Due to a small programming inattantion, they’ll add a second < character when autocompleting. This can be easily avoided by going to your sublime-completions file and adding a < in front of every trigger, i.e.:

{ "trigger": "body", "contents": "<body>$1</body>" },
becomes

{ "trigger": "<body", "contents": "<body>$1</body>" },

If you’re as new to Sublime as I was a few days earlier: mark one whole block at a time (but none of the empty lines) and press Ctrl+Shift+L to select every single line. now just use Pos1 and the arrow-keys to navigate to the beginning of the trigger and add the <. It’ll be added in all lines at once.

bw,
Tobl

0 Likes

#3

Renaming files will not prevent them from being found and used by ST, as long as they remain in the Packages area. Personally, I moved the html completions file completely out of the Packages directory and replaced them with my own versions, in a different folder. I am aware that these files will be re-instated on a future build or update, but this doesn’t concern me too much, as I will just delete or move them again.

The extra < that is inserted is usually caused by the **ZenCoding **package. If you have this package installed, but are not using, then you can disable it via PackageControl - or uninstall it.

0 Likes

#4

Hello,
Thanks for the tips. I usually rename my files by extension, for example “html_completions.py.deact”. They’re pretty dead that way, but I should’ve tried normal renaming before posting it here.

considering the < : My ST2-installation is only a day old and completely vanilla, so no, it’s not Zen. Mayby Zen changes the priorities from the .py- to the .sublime-completions-files and has that as a sideeffect, but the cause lies within the files. If you compare the python-files, you’ll see that they have the correct < from the beginning.

bw,
Tobl

0 Likes