Is there a way in Sublime to wrap a selection of text in two separately defined strings?

StackOverflow https://stackoverflow.com/questions/23297251

  •  09-07-2023
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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>

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top