DEV Community

Cover image for VSCode - Wrap HTML elements
Camilo Martinez
Camilo Martinez

Posted on • Edited on

VSCode - Wrap HTML elements

One of the best hidden ๐Ÿ’Ž that I found on VSCode is the HTML wrapper combined with Emmet and together are pure gold.

I can believe all the time I've lost doing the same manually when forgot/need to include a parent tag.

The hard way ๐Ÿ‘Ž

Creating a new element and then move the content inside with cut/paste or moving the lines with alt+verticalArrows.

Hard Way

The good way ๐Ÿ‘

Using the "Emmet Wrapper" option through the "Command Palette" using ctrl+shift+p.

Easy Way

The best way ๐ŸŒŸ

Adding a shortcut alt+shift+w for the "Emmet Wrapper" option.

Easiest

You also can define the shortcut manually.



# ๐Ÿ“„ File: keybindings.json
-----------------------------------

// Place your key bindings in this file to override the defaults
[
    // Emmet
    {
        "key": "alt+shift+w", //wrap emmet
        "command": "editor.emmet.action.wrapWithAbbreviation",
        "when": "editorHasSelection"
    },
]


Enter fullscreen mode Exit fullscreen mode

The Geek Way ๐Ÿค“

What if I tell you, that the whole process can be faster without using the mouse adding more useful shortcuts.



# ๐Ÿ“„ File: keybindings.json
-----------------------------------

// Place your key bindings in this file to override the defaults
[
  {
    "key": "alt+shift+j", //expand selection
    "command": "editor.emmet.action.balanceOut"
  },
  {
    "key": "alt+shift+k", //contact selection
    "command": "editor.emmet.action.balanceIn"
  },
]


Enter fullscreen mode Exit fullscreen mode

Balance Shortcut


Multicursor ๐Ÿ˜Ž

But the magic does not end, this wrapper is also available for multicursor.

Multicursor


You don't need that extension ๐Ÿšซ

By the way, you don't need an extension like html-tag-wrapper to achieve it.


Thatโ€™s All Folks!
Happy Coding
๐Ÿ––

beer

Top comments (0)