0

There are Live Templates, there is Emmet as well but I can't get with them what I need.

I want to change selected text like for example this:

About Us
Contact Us
Some other page

into:

<ul>
 <li><a href="/about-us">About Us</a><li>
 <li><a href="/contact-us">Contact Us</a><li>
 <li><a href="/some-other-page">Some other page</a><li>
</ul>

And it would be best if I could do that with a shortcut key.

I used that a lot in PHPEd By Nusphere but here I don't see such an option. There was there option: get selection, parse with PHP script via shell and output back to editor and that way I could do anything with selected text.

Is that possible with PhpStorm? Is there something that I could use to achieve this effect with just one click?

I can do a Live template for one line of text, I don't see possibility to cover more lines at once. Then I could at least get just list of <li>s without <ul>.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
TAwg
  • 1
  • Possibly you could do this with a macro and multi-cursor editing / column selection mode. Then bind a shortcut to that macro. I often use these modes manually to edit many lines at once. Combine that with Ctrl+Shift+U to toggle case and Ctrl+R replacing spaces with dashes, etc. – jlh Mar 30 '17 at 08:57
  • Well ... you can use `$SelectedText$` macro in [External Tools](https://confluence.jetbrains.com/display/PhpStorm/Running+External+Tools+in+PhpStorm) to pass such selection to your script .. but IDE has no mechanism to then replace original text it with the script output (unless you save the output into some predefined file and then copy-paste from there manually) – LazyOne Mar 30 '17 at 08:58
  • Other way -- just use Emmet functionality for common part and add unique part (URLs) later manually -- see http://stackoverflow.com/a/20095020/783119 as example – LazyOne Mar 30 '17 at 08:59
  • P.S. Finally found a ticket about such stuff (my 1st comment): https://youtrack.jetbrains.com/issue/IDEA-76371 – LazyOne Mar 30 '17 at 09:05
  • @LazyOne you are right as for the ExternalTools - it lacks the ability to return the outpiut back to the editor. I know I can use Emmet but in PHPEd I was doing such things just by selecting text and using a shortcut and it was saving a lot of time. – TAwg Mar 30 '17 at 15:07
  • I could use JavaScript to do it but is it possible? For example in Brackets it was easy to write a plugin to do such a thing. But in the end PHPStorm has the features I like more but lack the feature for parsing the selected text. – TAwg Mar 30 '17 at 15:18
  • I do not think that it can be done in PhpStorm unless you code plugin in Java/Kotlin. If it would be IntelliJ IDEA you could use GroovyScript... but it requires specific Java support code/functionality which is not available in PhpStorm. – LazyOne Mar 30 '17 at 15:32
  • Thank you. I wouldn't be able to write a plugin in Java/Kotlin ;) Thank you @LazyOne for suggestions. I think I will need to make some JavaScript snippets open in browser to do such tasks for me. – TAwg Mar 30 '17 at 15:34

0 Answers0