Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying HTML <script> auto complete on Sublime Text 2

In Sublime Text 2 when inserting an html script tag using auto complete the cursor jumps to the end of the tag.

<script type="text/javascript"></script>*CURSOR HERE*

How can i modify the auto completion in Sublime so when I tab-complete an html script tag a src-attribute is added to the tag and the cursor jumps to the quotes of the src-attribute?

I found the following line in the Sublime HTML.sublime-completions file:

{ "trigger": "script", "contents": "<script type=\"${1:text/javascript}\">$0</script>" }

I tried modifying it to the following:

{ "trigger": "script", "contents": "<script type=\"${1:text/javascript}\" src=\"$1\">$0</script>" }

For this I referenced the html link tag in the file:

{ "trigger": "link", "contents": "<link rel=\"stylesheet\" type=\"text/css\" href=\"$1\">" }

I tried installing another package called HTMLAttributes, but this didn't add the functionality i want.

I also tried modifying the script tag, i removed the type, but Sublime can still auto complete it. Am I modifying it wrong? Or in the wrong file?

Thanks for any help.

like image 839
Chennard Avatar asked Mar 25 '13 22:03

Chennard


1 Answers

Please try to add the following code in html_completions.py located in the packages folder.

("script\tTag", "script type=\"${2:text/javascript}\" src=\"$1\">$0</script>" ),

More information: http://docs.sublimetext.info/en/latest/reference/completions.html

like image 172
Jair Avatar answered Sep 23 '22 23:09

Jair