1

When I'm editing an HTML file, I start typing, for example,

<im

then SublimeText gives suggests it is gonna be an image tag (as it is), so I just hit Enter and get

<img src="">

It is good, but I want to have all tags of this kind (e.g. img, br, input, etc.) closed:

<img src="" />

or

<br/>

but I don't want to just create new snippets. I need to edit the existing default ones. Is there a way to do it, or I need to write my own snippets?

1 Answers1

1

Sublime's HTML autocompletions are done in a Python script.

  1. Install PackageResourceViewer using Package Control (if it isn't already installed)
  2. From the Command Palette, select PackageResourceViewer - Open Resource
  3. Select HTML
  4. Select html_completions.py
  5. Search for 'img src= (doesn't matter whether in RegEx or literal mode)
  6. On that line, insert the closing / before the >
  7. Do the same for other self-closing tags like br, hr, input and param
  8. Save the file

It seems that it was discussed to change the default but unfortunately the consensus at the time was that it isn't necessary in HTML5, despite being valid. Nobody brought up that not being self closing makes it impossible for the file to be parsed by an XML parser, so maybe it's worth logging a new issue/PR and seeing what happens. EDIT: an alternative solution might be to code it so that it picks up a preference, whether self-closing tags should be explicitly closed or not. That way, maybe everyone can be happy, and the PR would be more likely to be accepted :) ST is all about customization, after all ;)


Note that making this change will mean that you will have a html_completions.py file in your Packages/HTML folder overriding the one that ships with ST3. So if you upgrade to a newer build, and there have been changes to this file in the GitHub repo, you will want to delete your override file and re-apply the changes using the same steps above if necessary.

Community
  • 1
  • 1
Keith Hall
  • 15,362
  • 3
  • 53
  • 71
  • Keith Hall, whether it is planned to enter into Sublime Text the function or plugin allowing merge the user changes of files with new versions of files after updating Sublime Text? [**See also**](https://forum.sublimetext.com/t/how-to-save-the-changes-to-the-default-syntaxes-after-update-sublime-text-3/21698?u=sasha_chernykh). – Саша Черных Aug 11 '16 at 06:52
  • @СашаЧерных not as far as I know - which is why the best solution is to try to get any changes you want included as part of Sublime Text, and remove the need for these user changes. Whether it is by reporting bugs, requesting new features, or making Pull Requests to the default Packages - the more people that show they want something, the more likely the ST devs are to implement it (in my opinion). – Keith Hall Aug 11 '16 at 06:58