Shortcut for wraping a selected text with formating on/off?

I need to prevent some code for being formatted. Sometimes there are lot of lines and typing manually

@formatter:off

my piece of code

@formatter:on

takes a lot of time.

What I need is to select some code and wrap the code with above statements.

Is there a way to achieve that?

7 comments
Comment actions Permalink

Hi there,

Live Template of surround kind?

Create template first, select text, apply.

https://confluence.jetbrains.com/display/PhpStorm/Live+Templates+%28Snippets%29+in+PhpStorm

 

2
Comment actions Permalink

It's perfect. I wasn't aware about surrounding templates. However I've got problem with assigning a keyboard shortcut to macro to get it works faster.

I recorded a two steps macro and assigned it to ctrl + shift + O

step 1. action surround with live template;

step 2. type "r"(it's from live template's abbreviation)

When I select target text and press ctrl + shif + O it shows me my livetemplates list

However when run macro manually from Edit -> Macros

It works great:

Do you have got any idea why it doesn't work with keyboard shortcut?

 

 

0
Comment actions Permalink

IDE version?

How do you press the shortcut? You need to press and release all keys at the same time. If you keep Ctrl and/or Shift key pressed while O is already released then it will not finish selecting template...

Also -- what was the macro sequence? I mean -- how did you select the needed template? As I understand you pressed the underlined letter r (so only 1 press needed). I suggest to use full abbreviation instead (as I understand it's "re" on your screenshot; type the actual abbreviation and confirm with Enter). Create couple of surround templates (for the same context) to see how it works.

1
Comment actions Permalink

Basically you were right about that: "If you keep Ctrl and/or Shift key pressed while O is already released then it will not finish selecting template..." You have to release all keys combination in very same time, which is nearly impossible at first time. However thank you very much for your help.

Regards macro they should have add more iddle time to wait for releasing all keys, because in this case it's impossible to use such combination in normal work.

 

0
Comment actions Permalink

I already wrote there. I left my comment here just for the record.

0
Comment actions Permalink

I see. Sorry for confusion.

0

Please sign in to leave a comment.