How to do tag wrapping in VS code?

后端 未结 7 1382
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 05:10

I would like to wrap my selected html within a tag in VS code. How do I do that?

7条回答
  •  佛祖请我去吃肉
    2020-12-04 05:58

    imo there's a better answer for this using Snippets

    Create a snippet with a definition like this:

    "name_of_your_snippet": {
        "scope": "javascript,html",
        "prefix": "name_of_your_snippet",
        "body": "<${0:b}>$TM_SELECTED_TEXT"
    }
    

    Then bind it to a key in keybindings.json E.g. like this:

    { 
        "key": "alt+w",
        "command": "editor.action.insertSnippet",
        "args": { "name": "name_of_your_snippet" }
    }
    

    I think this should give you exactly the same result as htmltagwrap but without having to install an extension.

    It will insert tags around selected text, defaults to tag & selects the tag so typing lets you change it.

    If you want to use a different default tag just change the b in the body property of the snippet.

提交回复
热议问题