Encapsulate set of HTML tags in VS Code ("Ctrl + alt + enter" in Sublime Text)

Asked

Viewed 5,607 times

2

Editing HTML files in Sublime Text I can encapsulate a set of tags or text just by selecting the block and pressing Ctrl+Alt+Enter and then typing in which tag I want to use to encapsulate the block. I would like to do the same in Visual Studio Code but so far I have no idea.

  • If you use Emmet you can select the text, press Ctrl + Shift + P and type wrap. One of the options is to wrap it with an Emmet expression.

  • Thanks, it worked, only I was actually looking for a more practical keyboard shortcut.

  • I did this same search a while ago and at the time there was no native shortcut. What you can do is add the above command to the shortcut file.

  • @fernandosavio jovem, to using the extension that I quoted there in the answer, has been quite useful, sometimes it interests you.

  • Already positive. I use very little this Feature so I’ll leave it favorite for when I need it. Thanks Hugo!

2 answers

5

I use this extension htmltagwrap you can find here: https://marketplace.visualstudio.com/items?itemName=bradgashler.htmltagwrap

This extension already comes with a defined shortcut, just select the bolus of text you want to package and separate Alt + W as you can see in the Gif below

inserir a descrição da imagem aqui


Editing the shortcut

If you want to change the original shortcut to one that pleases you more simply adjust here

inserir a descrição da imagem aqui

Now search and edit the new shortcut

inserir a descrição da imagem aqui

1


You can do this by setting a shortcut to the function emmet wrap of Visual Studio Code:

  1. Go on Code -> Preferences -> Keyboard Shortcuts.
  2. Look for emmet wrap.
  3. Click on the plus sign + of the option Emmet: Wrap with Abbreviation.
  4. Add the shortcut you want by pressing CTRL+ALT+ENTER, and then ENTER to confirm.
  5. Now just select a piece of HTML code and use the shortcut. A text box will appear for you to write the tag you want to wrap the text.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.