Vscode: [html] VSCode doesn't automatically close HTML tags

Created on 25 Jan 2016  路  18Comments  路  Source: microsoft/vscode

in html file-type
vscode version 0.10.6

My User Settings config says:
"editor.autoClosingBrackets": true,

but it still doesn't work.

For example, when you type in "

<script>
</script>

but it stays like this:

<script>
feature-request html on-testplan

Most helpful comment

Perhaps this is better as a separate feature request, but it would be useful to integrate auto tag renaming. It's currently available as a popular extension. Thanks.

All 18 comments

any update on it?

@cindoum Sorry, no, we currently have no plans adding this.
I recommend you using the emmet expansion
enter script, press tab. This expand to <script></script>

You can use the "Auto Close Tag" extension to replace this behaviour. IMO this is better so that VSCode can stay light and people can "enable" features with the extension of choice.

https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag

It is so essential that it should be part of the HTML language service.

Duplicate of #502 (?)

Yes, #502 is the same. I'll close #502 as dup.

+1 This makes coding faster.

Perhaps this is better as a separate feature request, but it would be useful to integrate auto tag renaming. It's currently available as a popular extension. Thanks.

You may want to use Auto Close Tag extension, and it supports for both Visual Studio mode and Sublime Text mode.

  • Visual Studio mode: <script> --> <script></script>
    Visual Studio
  • Sublime Text mode: <script></ --> <script></script>
    Sublime Text

Can't you use the https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributeslanguages ?

autoClosingPairs - Defines the open and close symbols for the auto-close functionality. When an open symbol is entered, the editor will insert the close symbol automatically. Auto closing pairs optionally take a notIn parameter to deactivate a pair inside strings or comments.

Feature makes it slightly annoying to add HTML to existing tags as it prefers to close the parent tag, instead of creating a new opening tag (I'll have to untrain hitting enter when writing HTML). Esp common occurence with div soup.

I added auto-close to the built-in HTML language support:

  • typing the > of <sometag> will add the closing tag </sometag>.
  • typing / of </ will also close the tag.
  • this behaviour is enabled by default and can be turned off with setting html.autoClosingTags

Thanks @formulahendry for leading the way with his extension. Note that the auto-close extension has more features, in particular, configurable support for more languages.
Jun, if you can add a check for the new setting that would be great, so the auto-close extension can co-exist with the new support.

Thanks @aeschli , that's cool! I will take a look.

Does it work also with JSX/TSX?

@rosieks No, this is only for html, handlebars and razor files.

Thx, @aeschli , you rock!

@formulahendry , how is @aeschli 's solution different from the Auto Close Tag extension?

@johnyradio

@aeschli 's solution is leveraging the VSCode built-in HTML extension. It could distinguish HTML and embedded languages well. So when you write embedded languages inside HTML, there will not be improper auto-close if you write generic like https://github.com/formulahendry/vscode-auto-close-tag/issues/17. While the limitation is that it only works on html, handlebars and razor files.

For Auto Close Tag extension, it is based on regular expression. So it works for any languages, while the limitation is that it could not distinguish HTML and embedded languages.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  234Comments

Perkovec picture Perkovec  路  191Comments

Tyriar picture Tyriar  路  187Comments

Tyriar picture Tyriar  路  200Comments

hsdk123 picture hsdk123  路  263Comments