Sublime Forum

Change the default tag for "wrap selection with tag" from p to div

#1

Hi, I am writing a lot of HTML using the “wrap selection with tag” feature. Every time it creates a tag it defaults to “p”, is there a way to change the tag by configuration to “div”?

If not, can you recommend any other way to accomplish this?

Many thanks
James

0 Likes

#2

There’s not a configuration for this, but this particular function is the result of a snippet being expanded. For example, the key bindings on Windows/Linux looks like this (formatted to not be one long line):

{ 
    "keys": ["alt+shift+w"], 
    "command": "insert_snippet", 
    "args": { "name": "Packages/XML/Snippets/long-tag.sublime-snippet" } 
}

The same command is executed for Ctrl+Shift+W on MacOS and by the menu entry Edit > Tag > Wrap selection with tag.

If you use PackageResourceViewer to open this snippet, you’ll see that it looks like this:

<snippet>
    <content><![CDATA[<${1:p}>${2:$SELECTION}</${1/([^ ]+).*/$1/}>]]></content>
    <tabTrigger>&lt;</tabTrigger>
    <scope>text.xml</scope>
    <description>Long Tag</description>
</snippet>

Changing ${1:p} to ${1:div} will make the default tag use div instead.

If you use PackageResourceViewer to open the file (PackageResourceViewer: Open Resource from the command palette, then select XML, then Snippets, then long-tag.sublime-snippet), you can make the change and save the result, which will override the default version with your changed version instead.

The alternative is to make a duplicate of the snippet in your User package (select Tools > Developer > New Snippet... from the menu and replace the contents, then save) and then add a key binding to your user settings that changes the snippet to be your User version instead. Doing so will leave the menu entry still using the original version, which may or may not be a problem for you.

4 Likes

#3

Wow! Thank you for such a great answer to the question. I ran through your instructions and it worked like a dream, instant productivity boost.

Kind regards
James

2 Likes