Programs » Sublime Text

Wrap Selection in a Tag, PHP, Snippet

1. Go to Tools -> New Snippet…

2. Change the content:

<snippet>
  <content><![CDATA[<?php $SELECTION$1 ?>]]></content>
  <scope>source.php</scope>
</snippet>
<snippet>
  <content><![CDATA[<div>$SELECTION$1</div>]]></content>
  <scope>text.html - source.php</scope>
</snippet>
<snippet>
  <content>
    <![CDATA[
      [OPEN_TETX] $SELECTION$1 [CLOSING_TEXT]
    ]]>
  </content>
  <scope>text.html - source.php</scope>
</snippet>

3. Save to a file with any name

4. Go to Preferences -> Key Bindings – User

5. Add the shortcut

{"keys": ["ctrl+shift+e"], "command": "insert_snippet","args":{"name": "Packages/User/php_wrap.sublime-snippet"}},

6. Test it: type “word”, select it and press the shortcut.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>