intellij-ideawebstormlive-templates

Surround multiple lines with quotes


I'm trying to build a live template that will work like the 'wrap in comment' live template (that puts a // before each selected line). For example, select multiple lines of text, click Code > Surround With > Single quotes (custom live template) and quotes will appear around each line.

E.g. from:

text1
text2
text3

to:

'text1'
'text2'
'text3'

Unfortunately the template I define:

'$SELECTION$'

produces:

'text1
text2
text3'  

which makes sense.

Is there any way to define a Live Template that will work on each line of my selection?


Solution

  • "Wrap in comment" is not a live template, but an action that is implemented in Java. In the same way, you can't accomplish what you need using a live template, but you can write a small plugin in Java to implement that feature. Please refer to the Editor Basics tutorial to get started with writing the plugin.