Sublime Forum

Apply HTML tags to selected text

#1

I’ve looked lotsa places for an answer to this. Honest! I want to know how to select say 3 lines of text or 3 words of text, and then apply HTML tags to the beginning and end of the selected text, for example, p tags

I’m very fond of ST – it has been a huge help to this semi-disabled boy! I’m saving my dollars to subscribe, – David

0 Likes

#2

You can select some text and then choose Edit > Tag > Wrap Selection with tag from the menu (or use the key binding you’ll see when you look there) to do this. The tag is <p> by default, but both the opening and closing tag names will be selected by default so you can immediately type something to replace them (e.g. div).

0 Likes

#3

FANTASTIC! Thank you.

0 Likes

#4

You could use snippets like:

<snippet>
    <content><![CDATA[<p>${SELECTION}$0</p>]]></content>
    <description>paragraaf</description>
	<tabTrigger>p</tabTrigger>
    <scope>text.html</scope>
</snippet>

I use a lot of them to wrap HTML-tags around imported plain text. Or to simply insert them. I all gave them a keybinding like <ctrl>+<shift>+p . Another example: I wrap quoted text with <ctrl>+<shift>+c to have a snippet with a styleasheet class (my language is Dutch):

<snippet>
    <content><![CDATA[<p class="citaatkader">&quot;${SELECTION}$0&quot;</p>]]></content>
    <description>citaat</description>
	<tabTrigger>ct</tabTrigger>
    <scope>text.html</scope>
</snippet>

Try it out!

1 Like

#5

I will! Thanks, Ger

0 Likes