Question

Here's what I'm looking to accomplish:

I want to select a phrase in Sublime Text 2 (let's use the phrase "Goodnight Moon" for example) and wrap that phrase with two separate strings that aren't standard HTML strings.

For example, I'd like to highlight "Goodnight Moon" in Sublime and turn that string into '<?php echo my_function("Goodnight Moon"); ?>'

So, the two strings that are doing the wrapping would be '<?php echo my_function("' and '"; ?>'

Something like this:

<?php echo my_function(" HIGHLIGHTED_STRING "); ?>

Any ideas on how to accomplish this with Sublime? I've tried Emmet (http://docs.emmet.io/actions/wrap-with-abbreviation) but I've only been able to get that to wrap a string in standard matching HTML tags.

Was it helpful?

Solution

You can try playing around with the Snippet functionality of Sublime Text. Here's a sample to get you started.

<snippet>
    <content><![CDATA[
<?php echo ${0:my_function}("${SELECTION}"; ?>
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

OTHER TIPS

You can use text node to type arbitrary text and $# placeholder to decide where to insert wrapped content.

E.g. in your case you should wrap your selected text with {<?php echo my_function("$#"); ?>} abbreviation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top