Custom surround template

2019-02-06 12:56发布

问题:

How can I define my own custom surround template that I can use to wrap around a selection of javascript code followed by reformat.

I've used Alt + Cmd + T to bring up this option panel.

回答1:

Go to Settings/Live Templates, create a new Live template, specify abbreviation, description and contexts, check Reformat according to code style.

And now the important part. The Live template content must contain $SELECTION$ variable for it to be applicable for Surround with action. For instance:

console.log($SELECTION$);

After you save the template you should see it in the pop-up list next time you use the Surround With action.