Sublime Forum

How do I wrap selection in a tag?

#1

I’ve recently converted from E-Texteditor and one of the only features i miss it the ablity to wrap a selection in a html tag.

I would highlight the selection > press ctrl alt w > and type the tag letters “p”. Is this possible with sublime?

0 Likes

Dev Build 2033
#2

In Sublime Text all easier — highlight the selection, type tag name and press the tab key.

0 Likes

#3

Very cool :smile:

Thanks!

0 Likes

#4

when I do that, it just replaces the selection with the tag (e.g., ‘p’) and tab, literally. syntax is set to html.

0 Likes

#5

Firstly it replaces the selection with typed tag, but after pressing tab key the selection reappears already inside the tag.

Or something I do not understand and this functionality is dependent on any plug-ins? http://forums.disenteria.ru/style_emoticons/default/upset.gif

0 Likes

#6

Wrapping the text as ilya described is the default behaviour, perhaps this has been changed for you by a plugin.

0 Likes

#7

Jon, I think I found a possible bug.

I did a clean reinstall to find where the problem is and traced it to my keymap file. If I use mine keymap instead of Default, it breaks the tag wrap behavior. So I copied Default.sublime-keymap to temp.sublime-keymap to get a fresh restart. But without changing anything else, just setting

keymap temp

in Application.sublime-options breaks the tag wrap.

Then I copied and pasted my keymap file into Default.sublime-keymap and set it back to

keymap Default

and the wrap tag behavior is OK!

0 Likes

#8

if you take a look in the PowerUser package I provided I made a textmatetag.sublime-snippet…

basically it allows you to wrap an elemnt in a tag just exactly as it works in textmate or e-text
and for those that don’t want to bother downloading the package here it is…

[code]

[/code]

and the snippet…

<snippet> <content><![CDATA[<${1:p}>${0:$SELECTION}</${1/\s.*//}>]]></content> </snippet>

the regex in the snippet makes sure that when you type a tag with attributes the attributes don’t get mirrored in the closing tag… default behavior in sublime it does… not good :stuck_out_tongue:

0 Likes

#9

[quote=“barty”]Jon, I think I found a possible bug.

I did a clean reinstall to find where the problem is and traced it to my keymap file. If I use mine keymap instead of Default, it breaks the tag wrap behavior. So I copied Default.sublime-keymap to temp.sublime-keymap to get a fresh restart. But without changing anything else, just setting

keymap temp

in Application.sublime-options breaks the tag wrap.

Then I copied and pasted my keymap file into Default.sublime-keymap and set it back to

keymap Default

and the wrap tag behavior is OK![/quote]

I figured out my problem: the wrap tag function requires Default.sublime-keymap in the html package. When I change the keymap file to something other than Default, that file no longer gets loaded so the wrap tag feature (and others) no longer works.

0 Likes

#10

Hi there!

I realize this is an old thread but I’m trying to achieve the same thing as the original poster and I’m having the same problems except that I have a clean install of Sublime Text 2. I’m on OSX and I looked in ~/Library/Application Support/Sublime Text 2 and opened files that made sense to me but I can’t figure it out. Any help/pointers you guys can give me would be great!

Thanks :smile:

0 Likes

#11

The above mechanisms won’t work with Sublime Text 2, however I’m planning on adding tag wrapping to the next version

0 Likes

#12

In ST2 I miss this behavior: Select text > type tag > press tab > selected text become wrapped with typed tag.

This will implemented in next version? Next beta of ST2 or next version of ST3? :smile:

0 Likes

#13

Yay! Coudnt wait to hear it :smiley: <3

0 Likes

#14

Nice… I’ll be waiting for wrap feature too:)

0 Likes

#15

Just add this into your keymak conf file:

	{ 
		"keys"		:	"alt+shift+w"], 
		"command"	:	"insert_snippet",
		"args": {
			"contents": "<${1:p}>${0:$SELECTION}</${1}>"
		}
	}
0 Likes

#16

thank you!!! works epic

0 Likes

#17

[quote=“ilya”]In ST2 I miss this behavior: Select text > type tag > press tab > selected text become wrapped with typed tag.

This will implemented in next version? Next beta of ST2 or next version of ST3? :smile:[/quote]

I miss this too.

0 Likes

#18

[quote=“etune”]

[quote=“ilya”]In ST2 I miss this behavior: Select text > type tag > press tab > selected text become wrapped with typed tag.

This will implemented in next version? Next beta of ST2 or next version of ST3? :smile:[/quote]

I miss this too.[/quote]

There’s the tag plugin for this now: github.com/sublimetext/tag

0 Likes

#19

i always replace the selection with the tag and tab, literally. syntax is set to html.

0 Likes

#20

I had this same problem this morning. Looks like there are plugins/snippets that will work, but Control + Shift + W accomplished this for me.

0 Likes