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?
"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.
You can use find and replace feature in IntelliJ :
^(.+)$
(make sure to enable regex search with the *
next to the find field).'$1'
and if you need to put a ,
after '$1'
,
instead.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With