Code reformatting on save in PhpStorm or other jetbrains ide
Solution 1:
Actually it is possible.
The idea is to record a very simple macro that selects all the lines (Ctrl+A), formats (Ctrl+Alt+L), deselect all (Up and Down arrow) and saves a file (Ctrl+S), and bind this macro to Ctrl+S.
Free Ctrl+S changing keyboard shortcut for "Save all"
- open File > Settings;
- search for "keymap" and open it;
- search "Save All" and double click the action "Save all";
- select "Remove Ctrl+S";
- double click "Save All" again and select "Add Keyboard Shortcut";
- select "Ctrl+Alt+Shift+S" as first stroke.
- Confirm and exit from Settings.
Record the macro
- Edit > Macros > Start Macro recording
- Press Ctrl+A, then Ctrl+Alt+L, then Up arrow, then Down arrow, and finally then Ctrl+Alt+Shift+S
- Stop recording the macro clicking on the Stop button on the bottom right of the page.
- Give this macro a name like "Format and Save"
Assign Ctrl+S to "Format and Save"
- open File > Settings;
- search for "keymap" and open it;
- search "Format and Save" and double click the action "Format and Save";
- select "Add Keyboard Shortcut";
- select "Ctrl+S" as first stroke.
- Confirm and exit from Settings.
Finally, enjoy PhpStorm!
Solution 2:
I use Save Actions Plugin https://plugins.jetbrains.com/plugin/7642-save-actions for PhpSorm