Sublime Forum

How do I wrap selection in a tag?

#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

#21

Funny. Ctrl+Shift+W is like furthest away from a solution for me; it closes the application altogether.

Maybe you mean ALT+Shift+W, which works like a charm.

0 Likes