Search code examples
phpstormphpstorm-2018.1

PhpStorm - Duplicate lines down not working correctly


Duplicating lines does not work properly, e.g. if I try to duplicate the lines in the following screenshot:

enter image description here

then I get this:

enter image description here

instead of this:

enter image description here

Is there a setting so I can change this behaviour so that it works just like in NetBeans?


Solution

  • Is there a setting so I can change this behaviour so that it works just like in NetBeans?

    For "Duplicate Selection" action (which is what you are using) -- No; there is no such option (to auto reformat code after such operation or whatnot) and you will have to make "proper" selection (to include whole lines) to have desired behaviour.

    Currently this action (Duplicate Selection) behaves correctly: it duplicates only selected text and nothing else.

    But .. you can use "Duplicate Entire Lines" action instead ... which will duplicate WHOLE lines where selection is present (even if it's only one character selected on that line).

    Just assign desired shortcut and use where needed.

    • Settings/Preferences | Keymap
    • Type duplicate into local search box to narrow possible results
    • Locate Editor Actions | Duplicate Entire Lines in those results

    enter image description here