Sublime Text: Wrapping content with tag
To wrap your selected content with a html tag, just selected your text, then press Alt-Shift-W. You'll then have the option to fill in the front and back tag simultaneously.
Written by Matt
Related protips
14 Responses
Ctrl-Shift-W on a mac
Turns out you can use a zencoding-like syntax with this! For example, if you select text, hit the key combo, then type span.this.is.awesome#stuff>a[href="http://my.mind.is.blo.wn/index.html"], your text will be wrapped as expected with a span with classes "this" "is" and "awesome and an id of "stuff", and inside that, but still wrapping your text, an a tag with an href value matching the above!
I do have the zencoding plugin enabled, so this may be specific to that extension. Still it is quite awesome!
@epocsquadron You're right, if you have zencoding and you're doing this on an html file, they key combo will bring up the zencoding input box for you to use. Awesome tip!
In addition, Ctrl + Shift + Enter does the same operations. Nice tip. Thanks..
Really useful. thanks
@aliemreeee I don't think so! It just add a new line before the content.
Btw, don't try Ctrl-Shift-W on Windows.
ctrl-shift-g works for me on both Ubuntu and windows. I have emmet installed.
How does it know which tag to use?
It doesn't ask me for a tag, it just knew that I wanted a P-tag in my particular case. Is there a place to set it?
Thanks, rvinay88, ctrl-g was the option I was after.
@epocsquadron You made my day!
Further to what @epocsquadron said - if you want zen-coding in Sublime Text 2/3 get the Emmet plugin: http://docs.emmet.io/
Great tip that just added at least another 20 years of spare time onto my life!!!!!
CTRL + SHIFT + W on Mac. It does default to
but you can just start typing the tag you want and both open and close tags will update.
Alt + F4 on windows.